1333
This commit is contained in:
parent
7d1fbe4a23
commit
2b98bde808
@ -12,17 +12,17 @@ import (
|
||||
func Auth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 获取用户id
|
||||
userId := c.GetInt64("UserId")
|
||||
if userId == 0 {
|
||||
adminUserId := c.GetInt64("AdminUserId")
|
||||
if adminUserId == 0 {
|
||||
responses.Fail(c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil || user == nil {
|
||||
adminUserDao := dao.AdminUserDao{}
|
||||
adminUser, err := adminUserDao.GetAdminUserById(adminUserId)
|
||||
if err != nil || adminUser == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户数据错误",
|
||||
"code": consts.UserStatusError,
|
||||
@ -32,9 +32,9 @@ func Auth() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
if user.UserStatus == 2 {
|
||||
if adminUser.Status == 2 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户已禁用",
|
||||
"message": "用户审核中",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
@ -42,6 +42,38 @@ func Auth() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.Status == 3 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户状态异常",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.IsDisabled == 1 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户已被禁用",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.IsDeleted == 1 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户状态异常",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("AdminUserId", adminUserId) // 用户id
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ func Jwt() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("UserId", userId) // 用户id
|
||||
c.Set("AdminUserId", userId) // 用户id
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user