fix: 超管账号跳过强制改密码

This commit is contained in:
TsMask
2025-04-01 20:40:09 +08:00
parent 01df7b745b
commit afbb1e6ef4

View File

@@ -75,11 +75,18 @@ func (s AccountController) Login(c *gin.Context) {
return
}
// 强制改密码
forcePasswdChange, err := s.accountService.PasswordExpireTime(loginUser.User.LoginCount, loginUser.User.PasswordUpdateTime)
if err != nil {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
return
data := map[string]any{}
if !config.IsSystemUser(loginUser.UserId) {
// 强制改密码
forcePasswdChange, err := s.accountService.PasswordExpireTime(loginUser.User.LoginCount, loginUser.User.PasswordUpdateTime)
if err != nil {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
return
}
if forcePasswdChange {
data["forcePasswdChange"] = true
}
}
// 生成令牌,创建系统访问记录
@@ -96,15 +103,10 @@ func (s AccountController) Login(c *gin.Context) {
)
}
data := map[string]any{
"accessToken": tokenStr,
"tokenType": strings.TrimRight(constants.HEADER_PREFIX, " "),
"expiresIn": (loginUser.ExpireTime - loginUser.LoginTime) / 1000,
"userId": loginUser.UserId,
}
if forcePasswdChange {
data["forcePasswdChange"] = true
}
data["accessToken"] = tokenStr
data["tokenType"] = strings.TrimRight(constants.HEADER_PREFIX, " ")
data["expiresIn"] = (loginUser.ExpireTime - loginUser.LoginTime) / 1000
data["userId"] = loginUser.UserId
c.JSON(200, resp.OkData(data))
}
@@ -145,10 +147,12 @@ func (s AccountController) Me(c *gin.Context) {
"permissions": perms,
}
// 强制改密码
forcePasswdChange, _ := s.accountService.PasswordExpireTime(info.User.LoginCount, info.User.PasswordUpdateTime)
if forcePasswdChange {
data["forcePasswdChange"] = true
if !isSystemUser {
// 强制改密码
forcePasswdChange, _ := s.accountService.PasswordExpireTime(info.User.LoginCount, info.User.PasswordUpdateTime)
if forcePasswdChange {
data["forcePasswdChange"] = true
}
}
c.JSON(200, resp.OkData(data))
}