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/model/entity"
|
||||
userService "wechat-robot/service/adminuser"
|
||||
"wechat-robot/service/role"
|
||||
"wechat-robot/utils"
|
||||
)
|
||||
|
||||
@ -64,7 +65,8 @@ func ExtensionFields(ti oauth2.TokenInfo) (fieldsValue map[string]any) {
|
||||
_ = database.Client.Take(&ui, "id = ?", ti.GetUserID()).Error
|
||||
fieldsValue["username"] = ui.Username
|
||||
fieldsValue["id"] = ui.Id
|
||||
fieldsValue["roles"] = []string{"admin"}
|
||||
// 获取用户的角色代码
|
||||
fieldsValue["roles"] = role.GetCodesByUserId(ti.GetUserID())
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,16 @@ import (
|
||||
// @param userId string 用户Id
|
||||
// @return 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").
|
||||
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("tr.is_del IS FALSE").
|
||||
Take(&codes)
|
||||
return slices.Contains(codes, "admin")
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user