权限状态码更改
This commit is contained in:
parent
99d050cda1
commit
1eacef3a2d
@ -33,31 +33,51 @@ func Auth() gin.HandlerFunc {
|
||||
adminUserDao := dao.AdminUserDao{}
|
||||
adminUser, err := adminUserDao.GetAdminUserFirstById(userId)
|
||||
if err != nil || adminUser == nil {
|
||||
responses.FailWithMessage("用户数据错误", c)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户数据错误",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.Status == 2 {
|
||||
responses.FailWithMessage("用户审核中", c)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户审核中",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.Status == 3 {
|
||||
responses.FailWithMessage("用户已删除或禁用", c)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户已删除或禁用",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.RoleID == 0 {
|
||||
responses.FailWithMessage("用户角色错误", c)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户角色错误",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.IsDisabled == 1 {
|
||||
responses.FailWithMessage("用户已禁用", c)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户已禁用",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@ -72,14 +92,22 @@ func Auth() gin.HandlerFunc {
|
||||
adminRoleDao := dao.AdminRoleDao{}
|
||||
adminRole, err := adminRoleDao.GetAdminRoleFirstById(roleId)
|
||||
if err != nil || adminRole == nil {
|
||||
responses.FailWithMessage("角色错误", c)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "角色错误",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 检测角色是否已被禁用
|
||||
if adminRole.RoleStatus == 2 {
|
||||
responses.FailWithMessage("角色已被禁用", c)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "角色已被禁用",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@ -95,13 +123,21 @@ func Auth() gin.HandlerFunc {
|
||||
adminDeptDao := dao.AdminDeptDao{}
|
||||
adminDept, err := adminDeptDao.GetAdminDeptById(adminUser.DeptID)
|
||||
if err != nil || adminDept == nil {
|
||||
responses.FailWithMessage("用户部门数据错误", c)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户部门数据错误",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminDept.DeptStatus == 2 {
|
||||
responses.FailWithMessage("您所在的部门已被删除,请联系管理员修改", c)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "您所在的部门已被删除,请联系管理员修改",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@ -112,13 +148,21 @@ func Auth() gin.HandlerFunc {
|
||||
adminPostDao := dao.AdminPostDao{}
|
||||
adminPost, err := adminPostDao.GetAdminPostById(adminUser.PostID)
|
||||
if err != nil || adminPost == nil {
|
||||
responses.FailWithMessage("用户岗位数据错误", c)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户岗位数据错误",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminPost.PostStatus == 2 {
|
||||
responses.FailWithMessage("您所在的岗位已被删除,请联系管理员修改", c)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "您所在的岗位已被删除,请联系管理员修改",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user