From 267a13d3d6874870f30983d075dc948ff6463aa1 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Wed, 8 Nov 2023 14:58:00 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=8B=B1=E6=96=87=E8=BF=94=E5=9B=9E-common=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/common/controller/account.go | 11 +++++----- src/modules/common/controller/file.go | 14 ++++++------ src/modules/common/controller/index.go | 3 ++- src/modules/common/controller/register.go | 16 ++++++++------ src/modules/common/service/account.impl.go | 25 +++++++++++++--------- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/modules/common/controller/account.go b/src/modules/common/controller/account.go index 692dd1c8..07831e8c 100644 --- a/src/modules/common/controller/account.go +++ b/src/modules/common/controller/account.go @@ -36,7 +36,7 @@ type AccountController struct { func (s *AccountController) Login(c *gin.Context) { var loginBody commonModel.LoginBody if err := c.ShouldBindJSON(&loginBody); err != nil { - c.JSON(400, result.CodeMsg(400, "参数错误")) + c.JSON(400, result.CodeMsg(400, "parameter error")) return } @@ -74,8 +74,9 @@ func (s *AccountController) Login(c *gin.Context) { return } else { s.accountService.UpdateLoginDateAndIP(&loginUser) + // 登录成功 s.sysLogLoginService.CreateSysLogLogin( - loginBody.Username, commonConstants.STATUS_YES, "登录成功", + loginBody.Username, commonConstants.STATUS_YES, "Login Successful", ipaddr, location, os, browser, ) } @@ -133,13 +134,13 @@ func (s *AccountController) Logout(c *gin.Context) { // 当前请求信息 ipaddr, location := ctxUtils.IPAddrLocation(c) os, browser := ctxUtils.UaOsBrowser(c) - // 创建系统访问记录 + // 创建系统访问记录 退出成功 s.sysLogLoginService.CreateSysLogLogin( - userName, commonConstants.STATUS_YES, "退出成功", + userName, commonConstants.STATUS_YES, "Exit successful", ipaddr, location, os, browser, ) } } - c.JSON(200, result.OkMsg("退出成功")) + c.JSON(200, result.OkMsg("Exit successful")) } diff --git a/src/modules/common/controller/file.go b/src/modules/common/controller/file.go index c1f9076f..c160867b 100644 --- a/src/modules/common/controller/file.go +++ b/src/modules/common/controller/file.go @@ -27,7 +27,7 @@ type FileController struct{} func (s *FileController) Download(c *gin.Context) { filePath := c.Param("filePath") if len(filePath) < 8 { - c.JSON(400, result.CodeMsg(400, "参数错误")) + c.JSON(400, result.CodeMsg(400, "parameter error")) return } // base64解析出地址 @@ -71,13 +71,13 @@ func (s *FileController) Upload(c *gin.Context) { // 上传的文件 formFile, err := c.FormFile("file") if err != nil { - c.JSON(400, result.CodeMsg(400, "参数错误")) + c.JSON(400, result.CodeMsg(400, "parameter error")) return } // 子路径 subPath := c.PostForm("subPath") if _, ok := uploadsubpath.UploadSubpath[subPath]; !ok { - c.JSON(400, result.CodeMsg(400, "参数错误")) + c.JSON(400, result.CodeMsg(400, "parameter error")) return } @@ -109,7 +109,7 @@ func (s *FileController) ChunkCheck(c *gin.Context) { } err := c.ShouldBindJSON(&body) if err != nil { - c.JSON(400, result.CodeMsg(400, "参数错误")) + c.JSON(400, result.CodeMsg(400, "parameter error")) return } @@ -136,11 +136,11 @@ func (s *FileController) ChunkMerge(c *gin.Context) { } err := c.ShouldBindJSON(&body) if err != nil { - c.JSON(400, result.CodeMsg(400, "参数错误")) + c.JSON(400, result.CodeMsg(400, "parameter error")) return } if _, ok := uploadsubpath.UploadSubpath[body.SubPath]; !ok { - c.JSON(400, result.CodeMsg(400, "参数错误")) + c.JSON(400, result.CodeMsg(400, "parameter error")) return } @@ -171,7 +171,7 @@ func (s *FileController) ChunkUpload(c *gin.Context) { // 上传的文件 formFile, err := c.FormFile("file") if index == "" || identifier == "" || err != nil { - c.JSON(400, result.CodeMsg(400, "参数错误")) + c.JSON(400, result.CodeMsg(400, "parameter error")) return } diff --git a/src/modules/common/controller/index.go b/src/modules/common/controller/index.go index e295e10a..db200e6d 100644 --- a/src/modules/common/controller/index.go +++ b/src/modules/common/controller/index.go @@ -23,6 +23,7 @@ type IndexController struct{} func (s *IndexController) Handler(c *gin.Context) { name := config.Get("framework.name").(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))) } diff --git a/src/modules/common/controller/register.go b/src/modules/common/controller/register.go index 3e177e03..97526d0d 100644 --- a/src/modules/common/controller/register.go +++ b/src/modules/common/controller/register.go @@ -34,21 +34,24 @@ type RegisterController struct { func (s *RegisterController) Register(c *gin.Context) { var registerBody commonModel.RegisterBody if err := c.ShouldBindJSON(®isterBody); err != nil { - c.JSON(400, result.ErrMsg("参数错误")) + c.JSON(400, result.ErrMsg("parameter error")) return } // 判断必传参数 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 } 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 } 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 } @@ -74,12 +77,13 @@ func (s *RegisterController) Register(c *gin.Context) { userID, err := s.registerService.ByUserName(registerBody.Username, registerBody.Password, registerBody.UserType) if err == nil { - msg := registerBody.Username + " 注册成功 " + userID + msg := registerBody.Username + " registered success " + userID s.sysLogLoginService.CreateSysLogLogin( registerBody.Username, commonConstants.STATUS_YES, msg, ipaddr, location, os, browser, ) - c.JSON(200, result.OkMsg("注册成功")) + // 注册成功 + c.JSON(200, result.OkMsg("registered success")) return } c.JSON(200, result.ErrMsg(err.Error())) diff --git a/src/modules/common/service/account.impl.go b/src/modules/common/service/account.impl.go index 44089dff..8c8b4eb9 100644 --- a/src/modules/common/service/account.impl.go +++ b/src/modules/common/service/account.impl.go @@ -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 }