forked from lxh/go-wxhelper
✨ 逻辑完善,登录接口返回用户角色代码
This commit is contained in:
parent
379e2bdb54
commit
0aae8e36eb
@ -12,6 +12,7 @@ import (
|
|||||||
"wechat-robot/internal/database"
|
"wechat-robot/internal/database"
|
||||||
"wechat-robot/model/entity"
|
"wechat-robot/model/entity"
|
||||||
userService "wechat-robot/service/adminuser"
|
userService "wechat-robot/service/adminuser"
|
||||||
|
"wechat-robot/service/role"
|
||||||
"wechat-robot/utils"
|
"wechat-robot/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -64,7 +65,8 @@ func ExtensionFields(ti oauth2.TokenInfo) (fieldsValue map[string]any) {
|
|||||||
_ = database.Client.Take(&ui, "id = ?", ti.GetUserID()).Error
|
_ = database.Client.Take(&ui, "id = ?", ti.GetUserID()).Error
|
||||||
fieldsValue["username"] = ui.Username
|
fieldsValue["username"] = ui.Username
|
||||||
fieldsValue["id"] = ui.Id
|
fieldsValue["id"] = ui.Id
|
||||||
fieldsValue["roles"] = []string{"admin"}
|
// 获取用户的角色代码
|
||||||
|
fieldsValue["roles"] = role.GetCodesByUserId(ti.GetUserID())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,16 @@ import (
|
|||||||
// @param userId string 用户Id
|
// @param userId string 用户Id
|
||||||
// @return flag bool 是否是超级管理员用户
|
// @return flag bool 是否是超级管理员用户
|
||||||
func CheckIsSuperAdminUser(userId string) (flag bool) {
|
func CheckIsSuperAdminUser(userId string) (flag bool) {
|
||||||
var codes []string
|
// 获取用户角色代码
|
||||||
|
codes := GetCodesByUserId(userId)
|
||||||
|
return slices.Contains(codes, "admin")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCodesByUserId
|
||||||
|
// @description: 根据用户Id获取用户的角色代码
|
||||||
|
// @param userId string 用户Id
|
||||||
|
// @return codes []string 角色代码
|
||||||
|
func GetCodesByUserId(userId string) (codes []string) {
|
||||||
// 获取用户角色代码
|
// 获取用户角色代码
|
||||||
database.Client.Table("t_role AS tr").
|
database.Client.Table("t_role AS tr").
|
||||||
Joins("LEFT JOIN t_admin_user_role AS tur ON tur.role_id = tr.id").
|
Joins("LEFT JOIN t_admin_user_role AS tur ON tur.role_id = tr.id").
|
||||||
@ -18,5 +27,5 @@ func CheckIsSuperAdminUser(userId string) (flag bool) {
|
|||||||
Where("tur.user_id = ?", userId).
|
Where("tur.user_id = ?", userId).
|
||||||
Where("tr.is_del IS FALSE").
|
Where("tr.is_del IS FALSE").
|
||||||
Take(&codes)
|
Take(&codes)
|
||||||
return slices.Contains(codes, "admin")
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user