...
|
...
|
@@ -8,6 +8,7 @@ import ( |
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
serverbac "oppmg/services/rbac"
|
|
|
"oppmg/services/ucenter"
|
|
|
"oppmg/storage/redisdata"
|
|
|
"oppmg/utils"
|
...
|
...
|
@@ -237,6 +238,8 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
if err != nil {
|
|
|
log.Error("更新用户数据失败:%s", err)
|
|
|
}
|
|
|
|
|
|
InitPermission(usercompanyid)
|
|
|
return logintoken, err
|
|
|
}
|
|
|
|
...
|
...
|
@@ -474,6 +477,7 @@ func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, err |
|
|
if err != nil {
|
|
|
log.Error("更新用户数据失败:%s", err)
|
|
|
}
|
|
|
InitPermission(usercompanyid)
|
|
|
return logintoken, err
|
|
|
}
|
|
|
|
...
|
...
|
@@ -504,7 +508,42 @@ func SmsCodeCheck(phone string, code string) error { |
|
|
}
|
|
|
|
|
|
//InitPermission 登录时权限初始化
|
|
|
func InitPermission(usercompanyid int, userid int64) error {
|
|
|
|
|
|
func InitPermission(usercompanyid int64) error {
|
|
|
var (
|
|
|
err error
|
|
|
permissionMap map[string]serverbac.PermissionOptionObject
|
|
|
)
|
|
|
permissionMap, err = serverbac.GetUserPermission(usercompanyid)
|
|
|
if err != nil {
|
|
|
log.Error("获取用户的权限失败")
|
|
|
return err
|
|
|
}
|
|
|
err = redisdata.SetUserPermission(permissionMap, usercompanyid)
|
|
|
if err != nil {
|
|
|
log.Error("缓存用户权限失败:%s", err)
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func ValidUserPermission(urlPath string, userid int64, companyid int64) bool {
|
|
|
var (
|
|
|
err error
|
|
|
permissionbase serverbac.PermissionBase
|
|
|
ok bool = false
|
|
|
permissionObj serverbac.PermissionOptionObject
|
|
|
)
|
|
|
permissionbase, ok = serverbac.RouterPermission[urlPath]
|
|
|
if !ok {
|
|
|
return true
|
|
|
}
|
|
|
permissionObj, err = redisdata.GetUserPermission(userid, permissionbase.CodeName)
|
|
|
if err != nil {
|
|
|
log.Error("未取到权限数据")
|
|
|
return false
|
|
|
}
|
|
|
ok = permissionObj.GetValidFunc(permissionbase.ActionName)
|
|
|
if ok {
|
|
|
return true
|
|
|
}
|
|
|
return false
|
|
|
} |
...
|
...
|
|