Skip to content

Commit

Permalink
cn
Browse files Browse the repository at this point in the history
  • Loading branch information
li-peifeng committed Sep 10, 2024
1 parent c5fb0ae commit c756184
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions server/common/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ func ParseToken(tokenString string) (*UserClaims, error) {
return SecretKey, nil
})
if IsTokenInvalidated(tokenString) {
return nil, errors.New("token is invalidated")
return nil, errors.New("令牌已失效")
}
if err != nil {
if ve, ok := err.(*jwt.ValidationError); ok {
if ve.Errors&jwt.ValidationErrorMalformed != 0 {
return nil, errors.New("that's not even a token")
return nil, errors.New("这不是一个令牌")
} else if ve.Errors&jwt.ValidationErrorExpired != 0 {
return nil, errors.New("token is expired")
return nil, errors.New("令牌已过期")
} else if ve.Errors&jwt.ValidationErrorNotValidYet != 0 {
return nil, errors.New("token not active yet")
return nil, errors.New("令牌尚未激活")
} else {
return nil, errors.New("couldn't handle this token")
return nil, errors.New("无法处理此令牌")
}
}
}
if claims, ok := token.Claims.(*UserClaims); ok && token.Valid {
return claims, nil
}
return nil, errors.New("couldn't handle this token")
return nil, errors.New("无法处理此令牌")
}

func InvalidateToken(tokenString string) error {
Expand Down
12 changes: 6 additions & 6 deletions server/middlewares/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Auth(c *gin.Context) {
return
}
if guest.Disabled {
common.ErrorStrResp(c, "Guest user is disabled, login please", 401)
common.ErrorStrResp(c, "游客账户已禁用,请登录!", 401)
c.Abort()
return
}
Expand All @@ -59,12 +59,12 @@ func Auth(c *gin.Context) {
}
// validate password timestamp
if userClaims.PwdTS != user.PwdTS {
common.ErrorStrResp(c, "Password has been changed, login please", 401)
common.ErrorStrResp(c, "密码已更改,请重新登录!", 401)
c.Abort()
return
}
if user.Disabled {
common.ErrorStrResp(c, "Current user is disabled, replace please", 401)
common.ErrorStrResp(c, "当前账户已停用", 401)
c.Abort()
return
}
Expand Down Expand Up @@ -113,12 +113,12 @@ func Authn(c *gin.Context) {
}
// validate password timestamp
if userClaims.PwdTS != user.PwdTS {
common.ErrorStrResp(c, "Password has been changed, login please", 401)
common.ErrorStrResp(c, "密码已更改,请重新登录!", 401)
c.Abort()
return
}
if user.Disabled {
common.ErrorStrResp(c, "Current user is disabled, replace please", 401)
common.ErrorStrResp(c, "当前账户已停用", 401)
c.Abort()
return
}
Expand All @@ -130,7 +130,7 @@ func Authn(c *gin.Context) {
func AuthAdmin(c *gin.Context) {
user := c.MustGet("user").(*model.User)
if !user.IsAdmin() {
common.ErrorStrResp(c, "You are not an admin", 403)
common.ErrorStrResp(c, "您不是管理员哦", 403)
c.Abort()
} else {
c.Next()
Expand Down

0 comments on commit c756184

Please sign in to comment.