新增客户端管理功能,包括创建、编辑和删除客户端的API,更新用户管理功能,添加用户创建和编辑页面,优化管理员功能,增强用户和客户端的管理体验。

This commit is contained in:
2025-04-17 02:29:16 +08:00
parent d06e45e5d4
commit ff47bb2f6f
11 changed files with 823 additions and 77 deletions

View File

@@ -209,3 +209,58 @@ func generateSecureToken(length int) string {
}
return base64.RawURLEncoding.EncodeToString(b)
}
// GetClients 获取客户端列表(分页)
func (s *ClientService) GetClients(page, pageSize int) ([]ClientResponse, int64, error) {
var clients []models.Client
var total int64
// 获取总数
if err := s.db.Model(&models.Client{}).Count(&total).Error; err != nil {
return nil, 0, err
}
// 获取分页数据
offset := (page - 1) * pageSize
if err := s.db.Offset(offset).Limit(pageSize).Find(&clients).Error; err != nil {
return nil, 0, err
}
// 转换为响应格式
responses := make([]ClientResponse, len(clients))
for i, client := range clients {
// 解析 JSON 字段
var redirectURIs, grantTypes, responseTypes, scopes, contacts []string
json.Unmarshal(client.RedirectURIs, &redirectURIs)
json.Unmarshal(client.GrantTypes, &grantTypes)
json.Unmarshal(client.ResponseTypes, &responseTypes)
json.Unmarshal(client.Scopes, &scopes)
json.Unmarshal(client.Contacts, &contacts)
responses[i] = ClientResponse{
ClientID: client.ClientID,
ClientSecret: client.ClientSecret,
ClientIDIssuedAt: client.CreatedAt,
RedirectURIs: redirectURIs,
TokenEndpointAuthMethod: client.TokenEndpointAuthMethod,
GrantTypes: grantTypes,
ResponseTypes: responseTypes,
ClientName: client.ClientName,
ClientURI: client.ClientURI,
LogoURI: client.LogoURI,
Scope: func() string {
if len(scopes) > 0 {
return scopes[0]
}
return ""
}(),
Contacts: contacts,
TosURI: client.TosURI,
PolicyURI: client.PolicyURI,
SoftwareID: client.SoftwareID,
SoftwareVersion: client.SoftwareVersion,
}
}
return responses, total, nil
}