Fix: standardize the use of error codes related to login credentials
This commit is contained in:
parent
c87109c8b1
commit
055ed0e075
5 changed files with 9 additions and 7 deletions
2
assets
2
assets
|
@ -1 +1 @@
|
|||
Subproject commit fb8ca793edf7c928773a29bdc5ec451d80a82e5e
|
||||
Subproject commit 397bf4569cee2152d6663fc5dd2bcff4ea84a954
|
|
@ -35,7 +35,7 @@ func SignRequired() gin.HandlerFunc {
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.Err(serializer.CodeCheckLogin, err.Error(), err))
|
||||
c.JSON(200, serializer.Err(serializer.CodeCredentialInvalid, err.Error(), err))
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -52,6 +52,8 @@ const (
|
|||
CodeNotFound = 404
|
||||
// CodeUploadFailed 上传出错
|
||||
CodeUploadFailed = 40002
|
||||
// CodeCredentialInvalid 凭证无效
|
||||
CodeCredentialInvalid = 40001
|
||||
// CodeCreateFolderFailed 目录创建失败
|
||||
CodeCreateFolderFailed = 40003
|
||||
// CodeObjectExist 对象已存在
|
||||
|
|
|
@ -20,7 +20,7 @@ func StartLoginAuthn(c *gin.Context) {
|
|||
userName := c.Param("username")
|
||||
expectedUser, err := model.GetUserByEmail(userName)
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.Err(401, "用户不存在", err))
|
||||
c.JSON(200, serializer.Err(serializer.CodeNotFound, "用户不存在", err))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ func FinishLoginAuthn(c *gin.Context) {
|
|||
userName := c.Param("username")
|
||||
expectedUser, err := model.GetUserByEmail(userName)
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.Err(401, "用户邮箱或密码错误", err))
|
||||
c.JSON(200, serializer.Err(serializer.CodeCredentialInvalid, "用户邮箱或密码错误", err))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ func FinishLoginAuthn(c *gin.Context) {
|
|||
_, err = instance.FinishLogin(expectedUser, sessionData, c.Request)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.Err(401, "登录验证失败", err))
|
||||
c.JSON(200, serializer.Err(serializer.CodeCredentialInvalid, "登录验证失败", err))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -171,10 +171,10 @@ func (service *UserLoginService) Login(c *gin.Context) serializer.Response {
|
|||
|
||||
// 一系列校验
|
||||
if err != nil {
|
||||
return serializer.Err(401, "用户邮箱或密码错误", err)
|
||||
return serializer.Err(serializer.CodeCredentialInvalid, "用户邮箱或密码错误", err)
|
||||
}
|
||||
if authOK, _ := expectedUser.CheckPassword(service.Password); !authOK {
|
||||
return serializer.Err(401, "用户邮箱或密码错误", nil)
|
||||
return serializer.Err(serializer.CodeCredentialInvalid, "用户邮箱或密码错误", nil)
|
||||
}
|
||||
if expectedUser.Status == model.Baned || expectedUser.Status == model.OveruseBaned {
|
||||
return serializer.Err(403, "该账号已被封禁", nil)
|
||||
|
|
Loading…
Add table
Reference in a new issue