refactor(verify): 重构验证码配置结构并优化默认值设置
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 5m51s
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 5m51s
将验证码配置从直接使用config.VerifyCode改为使用内部verifyCodeConfig结构 优化默认值设置逻辑,提高代码可读性和维护性
This commit is contained in:
parent
c25147656b
commit
6b23ab8152
@ -18,6 +18,12 @@ type verifyConfig struct {
|
||||
EnableResetPasswordVerify bool
|
||||
}
|
||||
|
||||
type verifyCodeConfig struct {
|
||||
VerifyCodeExpireTime int64
|
||||
VerifyCodeLimit int64
|
||||
VerifyCodeInterval int64
|
||||
}
|
||||
|
||||
func Verify(svc *svc.ServiceContext) {
|
||||
logger.Debug("Verify config initialization")
|
||||
configs, err := svc.SystemModel.GetVerifyConfig(context.Background())
|
||||
@ -37,23 +43,27 @@ func Verify(svc *svc.ServiceContext) {
|
||||
|
||||
logger.Debug("Verify code config initialization")
|
||||
|
||||
var verifyCodeConfig config.VerifyCode
|
||||
var vcc verifyCodeConfig
|
||||
cfg, err := svc.SystemModel.GetVerifyCodeConfig(context.Background())
|
||||
if err != nil {
|
||||
logger.Errorf("[Init Verify Config] Get Verify Code Config Error: %s", err.Error())
|
||||
return
|
||||
}
|
||||
tool.SystemConfigSliceReflectToStruct(cfg, &verifyCodeConfig)
|
||||
tool.SystemConfigSliceReflectToStruct(cfg, &vcc)
|
||||
|
||||
if verifyCodeConfig.ExpireTime == 0 {
|
||||
verifyCodeConfig.ExpireTime = 900
|
||||
if vcc.VerifyCodeExpireTime == 0 {
|
||||
vcc.VerifyCodeExpireTime = 900
|
||||
}
|
||||
if verifyCodeConfig.Limit == 0 {
|
||||
verifyCodeConfig.Limit = 15
|
||||
if vcc.VerifyCodeLimit == 0 {
|
||||
vcc.VerifyCodeLimit = 15
|
||||
}
|
||||
if verifyCodeConfig.Interval == 0 {
|
||||
verifyCodeConfig.Interval = 60
|
||||
if vcc.VerifyCodeInterval == 0 {
|
||||
vcc.VerifyCodeInterval = 60
|
||||
}
|
||||
|
||||
svc.Config.VerifyCode = verifyCodeConfig
|
||||
svc.Config.VerifyCode = config.VerifyCode{
|
||||
ExpireTime: vcc.VerifyCodeExpireTime,
|
||||
Limit: vcc.VerifyCodeLimit,
|
||||
Interval: vcc.VerifyCodeInterval,
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user