i18n: add error codes related to sign up

pull/1277/head
HFO4 3 years ago
parent c9eefcb946
commit 46c6ee9be7

@ -1 +1 @@
Subproject commit 47493d67d7b08192a406f68cf2e9a31a46f37104 Subproject commit bb23d3e55b87b6de8e882e16628c2551c8840e6b

@ -112,6 +112,12 @@ const (
CodeInvalidTempLink = 40029 CodeInvalidTempLink = 40029
// CodeTempLinkExpired 临时链接过期 // CodeTempLinkExpired 临时链接过期
CodeTempLinkExpired = 40030 CodeTempLinkExpired = 40030
// CodeEmailExisted 邮箱已被使用
CodeEmailExisted = 40032
// CodeEmailSent 邮箱已重新发送
CodeEmailSent = 40033
// CodeUserCannotActivate 用户无法激活
CodeUserCannotActivate = 40034
// CodeDBError 数据库操作失败 // CodeDBError 数据库操作失败
CodeDBError = 50001 CodeDBError = 50001
// CodeEncryptError 加密失败 // CodeEncryptError 加密失败

@ -46,7 +46,7 @@ func (service *UserRegisterService) Register(c *gin.Context) serializer.Response
userNotActivated = true userNotActivated = true
user = expectedUser user = expectedUser
} else { } else {
return serializer.DBErr("此邮箱已被使用", err) return serializer.Err(serializer.CodeEmailExisted, "Email already in use", err)
} }
} }
@ -59,7 +59,7 @@ func (service *UserRegisterService) Register(c *gin.Context) serializer.Response
controller, _ := url.Parse("/api/v3/user/activate/" + userID) controller, _ := url.Parse("/api/v3/user/activate/" + userID)
activateURL, err := auth.SignURI(auth.General, base.ResolveReference(controller).String(), 86400) activateURL, err := auth.SignURI(auth.General, base.ResolveReference(controller).String(), 86400)
if err != nil { if err != nil {
return serializer.Err(serializer.CodeEncryptError, "无法签名激活URL", err) return serializer.Err(serializer.CodeEncryptError, "Failed to sign the activation link", err)
} }
// 取得签名 // 取得签名
@ -78,11 +78,11 @@ func (service *UserRegisterService) Register(c *gin.Context) serializer.Response
finalURL.String(), finalURL.String(),
) )
if err := email.Send(user.Email, title, body); err != nil { if err := email.Send(user.Email, title, body); err != nil {
return serializer.Err(serializer.CodeInternalSetting, "无法发送激活邮件", err) return serializer.Err(serializer.CodeFailedSendEmail, "Failed to send activation email", err)
} }
if userNotActivated == true { if userNotActivated == true {
//原本在上面要抛出的DBErr放来这边抛出 //原本在上面要抛出的DBErr放来这边抛出
return serializer.DBErr("用户未激活,已重新发送激活邮件", nil) return serializer.Err(serializer.CodeEmailSent, "User is not activated, activation email has been resent", nil)
} else { } else {
return serializer.Response{Code: 203} return serializer.Response{Code: 203}
} }
@ -97,12 +97,12 @@ func (service *SettingService) Activate(c *gin.Context) serializer.Response {
uid, _ := c.Get("object_id") uid, _ := c.Get("object_id")
user, err := model.GetUserByID(uid.(uint)) user, err := model.GetUserByID(uid.(uint))
if err != nil { if err != nil {
return serializer.Err(serializer.CodeNotFound, "用户不存在", err) return serializer.Err(serializer.CodeUserNotFound, "User not fount", err)
} }
// 检查状态 // 检查状态
if user.Status != model.NotActivicated { if user.Status != model.NotActivicated {
return serializer.Err(serializer.CodeNoPermissionErr, "该用户无法被激活", nil) return serializer.Err(serializer.CodeUserCannotActivate, "This user cannot be activated", nil)
} }
// 激活用户 // 激活用户

Loading…
Cancel
Save