feat: 配置控制首次登录密码修改

This commit is contained in:
TsMask
2025-04-18 17:09:30 +08:00
parent b708c8924b
commit e30069603d
6 changed files with 19 additions and 12 deletions

View File

@@ -79,7 +79,7 @@ func (s AccountController) Login(c *gin.Context) {
if !config.IsSystemUser(loginUser.UserId) {
// 强制改密码
forcePasswdChange, err := s.accountService.PasswordExpireTime(loginUser.User.LoginCount, loginUser.User.PasswordUpdateTime)
forcePasswdChange, err := s.accountService.PasswordCountOrExpireTime(loginUser.User.LoginCount, loginUser.User.PasswordUpdateTime)
if err != nil {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
return
@@ -149,7 +149,7 @@ func (s AccountController) Me(c *gin.Context) {
if !isSystemUser {
// 强制改密码
forcePasswdChange, _ := s.accountService.PasswordExpireTime(info.User.LoginCount, info.User.PasswordUpdateTime)
forcePasswdChange, _ := s.accountService.PasswordCountOrExpireTime(info.User.LoginCount, info.User.PasswordUpdateTime)
if forcePasswdChange {
data["forcePasswdChange"] = true
}

View File

@@ -145,10 +145,15 @@ func (s Account) passwordRetryCount(userName string) (string, int64, time.Durati
return retryKey, retryCountInt64, time.Duration(lockTime) * time.Minute, nil
}
// passwordRetryCount 密码过期时间
func (s Account) PasswordExpireTime(loginCount, passwordUpdateTime int64) (bool, error) {
// 首次登录
forcePasswdChange := loginCount < 1
// PasswordCountOrExpireTime 首次登录或密码过期时间
func (s Account) PasswordCountOrExpireTime(loginCount, passwordUpdateTime int64) (bool, error) {
forcePasswdChange := false
// 从数据库配置获取-首次登录密码修改
fristPasswdChangeStr := s.sysConfigService.FindValueByKey("sys.user.fristPasswdChange")
if parse.Boolean(fristPasswdChangeStr) {
forcePasswdChange = loginCount < 1 || passwordUpdateTime == 0
}
// 非首次登录,判断密码是否过期
if !forcePasswdChange {
alert, err := s.sysUserService.ValidatePasswordExpireTime(passwordUpdateTime)
@@ -157,7 +162,6 @@ func (s Account) PasswordExpireTime(loginCount, passwordUpdateTime int64) (bool,
}
forcePasswdChange = alert
}
return forcePasswdChange, nil
}