style: 错误信息英文返回-common 模块路由
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -45,16 +44,19 @@ func (s *AccountImpl) ValidateCaptcha(code, uuid string) error {
|
||||
return nil
|
||||
}
|
||||
if code == "" || uuid == "" {
|
||||
return errors.New("验证码信息错误")
|
||||
// 验证码信息错误
|
||||
return fmt.Errorf("Captcha message error")
|
||||
}
|
||||
verifyKey := cachekey.CAPTCHA_CODE_KEY + uuid
|
||||
captcha, _ := redis.Get("", verifyKey)
|
||||
if captcha == "" {
|
||||
return errors.New("验证码已失效")
|
||||
// 验证码已失效
|
||||
return fmt.Errorf("Captcha is no longer valid")
|
||||
}
|
||||
redis.Del("", verifyKey)
|
||||
if captcha != code {
|
||||
return errors.New("验证码错误")
|
||||
// 验证码错误
|
||||
return fmt.Errorf("Captcha error")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -72,20 +74,22 @@ func (s *AccountImpl) LoginByUsername(username, password string) (vo.LoginUser,
|
||||
// 查询用户登录账号
|
||||
sysUser := s.sysUserService.SelectUserByUserName(username)
|
||||
if sysUser.UserName != username {
|
||||
return loginUser, errors.New("用户不存在或密码错误")
|
||||
return loginUser, fmt.Errorf("User does not exist or wrong password")
|
||||
}
|
||||
if sysUser.DelFlag == common.STATUS_YES {
|
||||
return loginUser, errors.New("对不起,您的账号已被删除")
|
||||
// 对不起,您的账号已被删除
|
||||
return loginUser, fmt.Errorf("Sorry, your account has been deleted")
|
||||
}
|
||||
if sysUser.Status == common.STATUS_NO {
|
||||
return loginUser, errors.New("对不起,您的账号已禁用")
|
||||
return loginUser, fmt.Errorf("Sorry, your account has been disabled")
|
||||
}
|
||||
|
||||
// 检验用户密码
|
||||
compareBool := crypto.BcryptCompare(password, sysUser.Password)
|
||||
if !compareBool {
|
||||
redis.SetByExpire("", retrykey, retryCount+1, lockTime)
|
||||
return loginUser, errors.New("用户不存在或密码错误")
|
||||
// 用户不存在或密码错误
|
||||
return loginUser, fmt.Errorf("User does not exist or wrong password")
|
||||
} else {
|
||||
// 清除错误记录次数
|
||||
s.ClearLoginRecordCache(username)
|
||||
@@ -144,8 +148,9 @@ func (s *AccountImpl) passwordRetryCount(username string) (string, int64, time.D
|
||||
// 是否超过错误值
|
||||
retryCountInt64 := parse.Number(retryCount)
|
||||
if retryCountInt64 >= int64(maxRetryCount) {
|
||||
msg := fmt.Sprintf("密码输入错误 %d 次,帐户锁定 %d 分钟", maxRetryCount, lockTime)
|
||||
return retrykey, retryCountInt64, time.Duration(lockTime) * time.Minute, errors.New(msg)
|
||||
// 密码输入错误 %d 次,帐户锁定 %d 分钟
|
||||
errorMsg := fmt.Errorf("password entered incorrectly %d times, account locked for %d minutes", maxRetryCount, lockTime)
|
||||
return retrykey, retryCountInt64, time.Duration(lockTime) * time.Minute, errorMsg
|
||||
}
|
||||
return retrykey, retryCountInt64, time.Duration(lockTime) * time.Minute, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user