style: 错误信息英文返回-common 模块路由
This commit is contained in:
@@ -36,7 +36,7 @@ type AccountController struct {
|
|||||||
func (s *AccountController) Login(c *gin.Context) {
|
func (s *AccountController) Login(c *gin.Context) {
|
||||||
var loginBody commonModel.LoginBody
|
var loginBody commonModel.LoginBody
|
||||||
if err := c.ShouldBindJSON(&loginBody); err != nil {
|
if err := c.ShouldBindJSON(&loginBody); err != nil {
|
||||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +74,9 @@ func (s *AccountController) Login(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
s.accountService.UpdateLoginDateAndIP(&loginUser)
|
s.accountService.UpdateLoginDateAndIP(&loginUser)
|
||||||
|
// 登录成功
|
||||||
s.sysLogLoginService.CreateSysLogLogin(
|
s.sysLogLoginService.CreateSysLogLogin(
|
||||||
loginBody.Username, commonConstants.STATUS_YES, "登录成功",
|
loginBody.Username, commonConstants.STATUS_YES, "Login Successful",
|
||||||
ipaddr, location, os, browser,
|
ipaddr, location, os, browser,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -133,13 +134,13 @@ func (s *AccountController) Logout(c *gin.Context) {
|
|||||||
// 当前请求信息
|
// 当前请求信息
|
||||||
ipaddr, location := ctxUtils.IPAddrLocation(c)
|
ipaddr, location := ctxUtils.IPAddrLocation(c)
|
||||||
os, browser := ctxUtils.UaOsBrowser(c)
|
os, browser := ctxUtils.UaOsBrowser(c)
|
||||||
// 创建系统访问记录
|
// 创建系统访问记录 退出成功
|
||||||
s.sysLogLoginService.CreateSysLogLogin(
|
s.sysLogLoginService.CreateSysLogLogin(
|
||||||
userName, commonConstants.STATUS_YES, "退出成功",
|
userName, commonConstants.STATUS_YES, "Exit successful",
|
||||||
ipaddr, location, os, browser,
|
ipaddr, location, os, browser,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, result.OkMsg("退出成功"))
|
c.JSON(200, result.OkMsg("Exit successful"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type FileController struct{}
|
|||||||
func (s *FileController) Download(c *gin.Context) {
|
func (s *FileController) Download(c *gin.Context) {
|
||||||
filePath := c.Param("filePath")
|
filePath := c.Param("filePath")
|
||||||
if len(filePath) < 8 {
|
if len(filePath) < 8 {
|
||||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// base64解析出地址
|
// base64解析出地址
|
||||||
@@ -71,13 +71,13 @@ func (s *FileController) Upload(c *gin.Context) {
|
|||||||
// 上传的文件
|
// 上传的文件
|
||||||
formFile, err := c.FormFile("file")
|
formFile, err := c.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 子路径
|
// 子路径
|
||||||
subPath := c.PostForm("subPath")
|
subPath := c.PostForm("subPath")
|
||||||
if _, ok := uploadsubpath.UploadSubpath[subPath]; !ok {
|
if _, ok := uploadsubpath.UploadSubpath[subPath]; !ok {
|
||||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ func (s *FileController) ChunkCheck(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
err := c.ShouldBindJSON(&body)
|
err := c.ShouldBindJSON(&body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,11 +136,11 @@ func (s *FileController) ChunkMerge(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
err := c.ShouldBindJSON(&body)
|
err := c.ShouldBindJSON(&body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, ok := uploadsubpath.UploadSubpath[body.SubPath]; !ok {
|
if _, ok := uploadsubpath.UploadSubpath[body.SubPath]; !ok {
|
||||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ func (s *FileController) ChunkUpload(c *gin.Context) {
|
|||||||
// 上传的文件
|
// 上传的文件
|
||||||
formFile, err := c.FormFile("file")
|
formFile, err := c.FormFile("file")
|
||||||
if index == "" || identifier == "" || err != nil {
|
if index == "" || identifier == "" || err != nil {
|
||||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ type IndexController struct{}
|
|||||||
func (s *IndexController) Handler(c *gin.Context) {
|
func (s *IndexController) Handler(c *gin.Context) {
|
||||||
name := config.Get("framework.name").(string)
|
name := config.Get("framework.name").(string)
|
||||||
version := config.Get("framework.version").(string)
|
version := config.Get("framework.version").(string)
|
||||||
str := "欢迎使用%s后台管理框架,当前版本:%s,请通过前端管理地址访问。"
|
// str := "欢迎使用%s核心网管理平台,当前版本:%s,请通过前台地址访问。"
|
||||||
|
str := "Welcome to the %s Core Network Management Platform, current version: %s, please access via the frontend address."
|
||||||
c.JSON(200, result.OkMsg(fmt.Sprintf(str, name, version)))
|
c.JSON(200, result.OkMsg(fmt.Sprintf(str, name, version)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,21 +34,24 @@ type RegisterController struct {
|
|||||||
func (s *RegisterController) Register(c *gin.Context) {
|
func (s *RegisterController) Register(c *gin.Context) {
|
||||||
var registerBody commonModel.RegisterBody
|
var registerBody commonModel.RegisterBody
|
||||||
if err := c.ShouldBindJSON(®isterBody); err != nil {
|
if err := c.ShouldBindJSON(®isterBody); err != nil {
|
||||||
c.JSON(400, result.ErrMsg("参数错误"))
|
c.JSON(400, result.ErrMsg("parameter error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断必传参数
|
// 判断必传参数
|
||||||
if !regular.ValidUsername(registerBody.Username) {
|
if !regular.ValidUsername(registerBody.Username) {
|
||||||
c.JSON(200, result.ErrMsg("账号不能以数字开头,可包含大写小写字母,数字,且不少于5位"))
|
// 账号不能以数字开头,可包含大写小写字母,数字,且不少于5位
|
||||||
|
c.JSON(200, result.ErrMsg("The account cannot start with a number and can contain uppercase and lowercase letters, numbers, and no less than 5 digits"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !regular.ValidPassword(registerBody.Password) {
|
if !regular.ValidPassword(registerBody.Password) {
|
||||||
c.JSON(200, result.ErrMsg("登录密码至少包含大小写字母、数字、特殊符号,且不少于6位"))
|
// 登录密码至少包含大小写字母、数字、特殊符号,且不少于6位
|
||||||
|
c.JSON(200, result.ErrMsg("The login password should contain at least uppercase and lowercase letters, numbers, special symbols, and no less than 6 digits"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if registerBody.Password != registerBody.ConfirmPassword {
|
if registerBody.Password != registerBody.ConfirmPassword {
|
||||||
c.JSON(200, result.ErrMsg("用户确认输入密码不一致"))
|
// 用户确认输入密码不一致
|
||||||
|
c.JSON(200, result.ErrMsg("The user confirmed that the input password is inconsistent"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,12 +77,13 @@ func (s *RegisterController) Register(c *gin.Context) {
|
|||||||
|
|
||||||
userID, err := s.registerService.ByUserName(registerBody.Username, registerBody.Password, registerBody.UserType)
|
userID, err := s.registerService.ByUserName(registerBody.Username, registerBody.Password, registerBody.UserType)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
msg := registerBody.Username + " 注册成功 " + userID
|
msg := registerBody.Username + " registered success " + userID
|
||||||
s.sysLogLoginService.CreateSysLogLogin(
|
s.sysLogLoginService.CreateSysLogLogin(
|
||||||
registerBody.Username, commonConstants.STATUS_YES, msg,
|
registerBody.Username, commonConstants.STATUS_YES, msg,
|
||||||
ipaddr, location, os, browser,
|
ipaddr, location, os, browser,
|
||||||
)
|
)
|
||||||
c.JSON(200, result.OkMsg("注册成功"))
|
// 注册成功
|
||||||
|
c.JSON(200, result.OkMsg("registered success"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(200, result.ErrMsg(err.Error()))
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -45,16 +44,19 @@ func (s *AccountImpl) ValidateCaptcha(code, uuid string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if code == "" || uuid == "" {
|
if code == "" || uuid == "" {
|
||||||
return errors.New("验证码信息错误")
|
// 验证码信息错误
|
||||||
|
return fmt.Errorf("Captcha message error")
|
||||||
}
|
}
|
||||||
verifyKey := cachekey.CAPTCHA_CODE_KEY + uuid
|
verifyKey := cachekey.CAPTCHA_CODE_KEY + uuid
|
||||||
captcha, _ := redis.Get("", verifyKey)
|
captcha, _ := redis.Get("", verifyKey)
|
||||||
if captcha == "" {
|
if captcha == "" {
|
||||||
return errors.New("验证码已失效")
|
// 验证码已失效
|
||||||
|
return fmt.Errorf("Captcha is no longer valid")
|
||||||
}
|
}
|
||||||
redis.Del("", verifyKey)
|
redis.Del("", verifyKey)
|
||||||
if captcha != code {
|
if captcha != code {
|
||||||
return errors.New("验证码错误")
|
// 验证码错误
|
||||||
|
return fmt.Errorf("Captcha error")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -72,20 +74,22 @@ func (s *AccountImpl) LoginByUsername(username, password string) (vo.LoginUser,
|
|||||||
// 查询用户登录账号
|
// 查询用户登录账号
|
||||||
sysUser := s.sysUserService.SelectUserByUserName(username)
|
sysUser := s.sysUserService.SelectUserByUserName(username)
|
||||||
if sysUser.UserName != 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 {
|
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 {
|
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)
|
compareBool := crypto.BcryptCompare(password, sysUser.Password)
|
||||||
if !compareBool {
|
if !compareBool {
|
||||||
redis.SetByExpire("", retrykey, retryCount+1, lockTime)
|
redis.SetByExpire("", retrykey, retryCount+1, lockTime)
|
||||||
return loginUser, errors.New("用户不存在或密码错误")
|
// 用户不存在或密码错误
|
||||||
|
return loginUser, fmt.Errorf("User does not exist or wrong password")
|
||||||
} else {
|
} else {
|
||||||
// 清除错误记录次数
|
// 清除错误记录次数
|
||||||
s.ClearLoginRecordCache(username)
|
s.ClearLoginRecordCache(username)
|
||||||
@@ -144,8 +148,9 @@ func (s *AccountImpl) passwordRetryCount(username string) (string, int64, time.D
|
|||||||
// 是否超过错误值
|
// 是否超过错误值
|
||||||
retryCountInt64 := parse.Number(retryCount)
|
retryCountInt64 := parse.Number(retryCount)
|
||||||
if retryCountInt64 >= int64(maxRetryCount) {
|
if retryCountInt64 >= int64(maxRetryCount) {
|
||||||
msg := fmt.Sprintf("密码输入错误 %d 次,帐户锁定 %d 分钟", maxRetryCount, lockTime)
|
// 密码输入错误 %d 次,帐户锁定 %d 分钟
|
||||||
return retrykey, retryCountInt64, time.Duration(lockTime) * time.Minute, errors.New(msg)
|
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
|
return retrykey, retryCountInt64, time.Duration(lockTime) * time.Minute, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user