fix: align admin behavior and Kratos integrations

This commit is contained in:
2026-08-14 14:14:51 +08:00
parent 8c4c6ba661
commit e0b0e1d8c8
123 changed files with 4334 additions and 1877 deletions
+43 -1
View File
@@ -1,6 +1,9 @@
package biz
import "context"
import (
"context"
"errors"
)
type SecurityConfig struct {
ID uint
@@ -29,3 +32,42 @@ type SecurityRepo interface {
SecurityConfig(context.Context) (*SecurityConfig, error)
SaveSecurityConfig(context.Context, *SecurityConfig) error
}
func (uc *SettingsUsecase) UpdateSecurity(ctx context.Context, value *SecurityConfig) error {
if value.KeyLong < 1 || value.ImgWidth < 1 || value.ImgHeight < 1 || value.PwdMinLength < 1 || value.LimitWindow < 1 || value.LimitCount < 1 || value.LockThreshold < 1 || value.LockDuration < 1 || value.PwdExpireDays < 1 {
return errors.New("安全配置数值必须大于0")
}
return uc.SaveSecurityConfig(ctx, value)
}
func (uc *SettingsUsecase) ValidatePassword(value *SecurityConfig, password string) error {
if len([]rune(password)) < value.PwdMinLength {
return errors.New("密码长度不足")
}
hasUpper, hasLower, hasDigit, hasSpecial := false, false, false, false
for _, ch := range password {
switch {
case ch >= 'A' && ch <= 'Z':
hasUpper = true
case ch >= 'a' && ch <= 'z':
hasLower = true
case ch >= '0' && ch <= '9':
hasDigit = true
default:
hasSpecial = true
}
}
if value.PwdRequireUpper && !hasUpper {
return errors.New("密码必须包含大写字母")
}
if value.PwdRequireLower && !hasLower {
return errors.New("密码必须包含小写字母")
}
if value.PwdRequireDigit && !hasDigit {
return errors.New("密码必须包含数字")
}
if value.PwdRequireSpecial && !hasSpecial {
return errors.New("密码必须包含特殊字符")
}
return nil
}