feat: Implement Oauth2 login log service and repository
- Added Oauth2LogLoginService for managing user authorization logs. - Implemented methods for inserting logs, cleaning logs, and exporting log data. - Created a new file for Oauth2 login log service. refactor: Remove unused open_api module - Deleted the open_api.go file as it was not utilized in the project. fix: Update error codes in SysProfileController - Changed error codes for binding errors and user authentication errors to more descriptive values. fix: Update cache handling in SysConfig and SysDictType services - Modified Redis set operations to include expiration time for cached values. refactor: Update middleware authorization checks - Replaced PreAuthorize middleware with AuthorizeUser across multiple routes in system and tool modules for consistency. chore: Clean up trace and ws modules - Updated middleware authorization in trace and ws modules to use AuthorizeUser.
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"be.ems/src/framework/constants"
|
||||
"be.ems/src/framework/database/redis"
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
systemModel "be.ems/src/modules/system/model"
|
||||
systemService "be.ems/src/modules/system/service"
|
||||
@@ -81,7 +78,7 @@ func (s Register) ByUserName(username, password string) (int64, error) {
|
||||
if insertId > 0 {
|
||||
return insertId, nil
|
||||
}
|
||||
return 0, fmt.Errorf("failed to register user [%s]. Please contact the system administrator", username)
|
||||
return 0, fmt.Errorf("failed to register user [%s]. Please contact the GM", username)
|
||||
}
|
||||
|
||||
// registerRoleInit 注册初始角色
|
||||
@@ -93,45 +90,3 @@ func (s Register) registerRoleInit() []int64 {
|
||||
func (s Register) registerPostInit() []int64 {
|
||||
return []int64{}
|
||||
}
|
||||
|
||||
// ValidatePasswordPolicy 判断密码策略强度
|
||||
func (s Register) ValidatePasswordPolicy(password string, errLang string) (bool, string) {
|
||||
passwordPolicyStr := s.sysConfigService.FindValueByKey("sys.user.passwordPolicy")
|
||||
if passwordPolicyStr == "" {
|
||||
// 未配置密码策略
|
||||
return false, i18n.TKey(errLang, "config.sys.user.passwordPolicyNot")
|
||||
}
|
||||
var policy struct {
|
||||
MinLength int `json:"minLength"`
|
||||
SpecialChars int `json:"specialChars"`
|
||||
Uppercase int `json:"uppercase"`
|
||||
Lowercase int `json:"lowercase"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal([]byte(passwordPolicyStr), &policy)
|
||||
if err != nil {
|
||||
return false, err.Error()
|
||||
}
|
||||
|
||||
errMsg := i18n.TTemplate(errLang, "sys.user.passwordPolicyError", map[string]any{
|
||||
"minLength": policy.MinLength,
|
||||
"specialChars": policy.SpecialChars,
|
||||
"uppercase": policy.Uppercase,
|
||||
"lowercase": policy.Lowercase,
|
||||
})
|
||||
specialChars := len(regexp.MustCompile(`[!@#$%^&*(),.?":{}|<>]`).FindAllString(password, -1))
|
||||
if specialChars < policy.SpecialChars {
|
||||
return false, errMsg
|
||||
}
|
||||
|
||||
uppercase := len(regexp.MustCompile(`[A-Z]`).FindAllString(password, -1))
|
||||
if uppercase < policy.Uppercase {
|
||||
return false, errMsg
|
||||
}
|
||||
|
||||
lowercase := len(regexp.MustCompile(`[a-z]`).FindAllString(password, -1))
|
||||
if lowercase < policy.Lowercase {
|
||||
return false, errMsg
|
||||
}
|
||||
return true, ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user