feat: 完善平台总后台模块

This commit is contained in:
2026-07-27 00:18:42 +08:00
parent 073eb89762
commit 642980960e
197 changed files with 22356 additions and 1060 deletions

View File

@@ -23,12 +23,11 @@ type LoginRequest struct {
// LoginReply 是后台登录成功后的访问凭证与账号状态。
type LoginReply struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
Identity string `json:"identity"`
DisplayName string `json:"display_name"`
RoleCode string `json:"role_code"`
MustChangePassword bool `json:"must_change_password"`
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
Identity string `json:"identity"`
DisplayName string `json:"display_name"`
RoleCode string `json:"role_code"`
}
// Login 校验平台账号密码并签发 BSM JWT。
@@ -39,7 +38,7 @@ func Login(ctx *gin.Context) {
return
}
var account models.IdnAccount
var account models.PlatfromAccount
err := impl.DBService.Where("username = ?", strings.TrimSpace(request.Username)).First(&account).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
@@ -60,23 +59,22 @@ func Login(ctx *gin.Context) {
accessToken, err := token.New(env.Runtime.JwtSecretKey).GenerateJwt(
0,
account.Identity.String(),
account.Identity,
"platform_admin",
account.RoleCode,
account.PlatformRoleCode,
map[string]string{"username": account.Username, "display_name": account.DisplayName},
map[string]string{"must_change_password": boolText(account.MustChangePassword)},
nil,
)
if err != nil {
infra.Response.Error(ctx, err)
return
}
infra.Response.Success(ctx, LoginReply{
AccessToken: accessToken,
TokenType: "JWT",
Identity: account.Identity.String(),
DisplayName: account.DisplayName,
RoleCode: account.RoleCode,
MustChangePassword: account.MustChangePassword,
AccessToken: accessToken,
TokenType: "JWT",
Identity: account.Identity,
DisplayName: account.DisplayName,
RoleCode: account.PlatformRoleCode,
})
}
@@ -87,14 +85,14 @@ func CurrentProfile(ctx *gin.Context) {
infra.Response.Error(ctx, err)
return
}
var account models.IdnAccount
var account models.PlatfromAccount
if err := impl.DBService.Where("identity = ?", claims.Identity).First(&account).Error; err != nil {
infra.Response.Error(ctx, errcode.ErrRecordNotFound)
return
}
infra.Response.Success(ctx, gin.H{
"identity": account.Identity.String(), "username": account.Username, "display_name": account.DisplayName,
"role_code": account.RoleCode, "must_change_password": account.MustChangePassword, "mfa_enabled": account.MFAEnabled,
"identity": account.Identity, "username": account.Username, "display_name": account.DisplayName,
"avatar": account.Avatar, "role_code": account.PlatformRoleCode,
})
}
@@ -116,7 +114,7 @@ func ChangePassword(ctx *gin.Context) {
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
return
}
var account models.IdnAccount
var account models.PlatfromAccount
if err := impl.DBService.Where("identity = ?", claims.Identity).First(&account).Error; err != nil {
infra.Response.Error(ctx, errcode.ErrRecordNotFound)
return
@@ -130,17 +128,9 @@ func ChangePassword(ctx *gin.Context) {
infra.Response.Error(ctx, err)
return
}
if err := impl.DBService.Model(&account).Updates(map[string]any{"password_hash": string(passwordHash), "must_change_password": false}).Error; err != nil {
if err := impl.DBService.Model(&account).Update("password_hash", string(passwordHash)).Error; err != nil {
infra.Response.Error(ctx, err)
return
}
infra.Response.Success(ctx, gin.H{"changed": true})
}
// boolText 将布尔值转换为 JWT 扩展字段约定的字符串。
func boolText(value bool) string {
if value {
return "true"
}
return "false"
}