...
|
...
|
@@ -143,30 +143,6 @@ func ChangeLoginToken(userid, companyid int64) (protocol.LoginAuthToken, error) |
|
|
return logintoken, nil
|
|
|
}
|
|
|
|
|
|
// func RefreshLoginToken(refreshtoken string) (protocol.LoginAuthToken, error) {
|
|
|
// var (
|
|
|
// logintoken protocol.LoginAuthToken
|
|
|
// mtoken *MyToken
|
|
|
// err error
|
|
|
// storetoken redisdata.RedisLoginToken
|
|
|
// )
|
|
|
// mtoken, err = ValidJWTToken(refreshtoken)
|
|
|
// if err != nil {
|
|
|
// log.Debug("token失效 err:%s", err)
|
|
|
// return logintoken, protocol.NewErrWithMessage("10024")
|
|
|
// }
|
|
|
// storetoken, err = redisdata.GetLoginToken(mtoken.UID, mtoken.CompanyID)
|
|
|
// if err != nil {
|
|
|
// log.Error("redis err:%s", err)
|
|
|
// return logintoken, protocol.NewErrWithMessage("10024")
|
|
|
// }
|
|
|
// if storetoken.RefreshToken != refreshtoken {
|
|
|
// return logintoken, protocol.NewErrWithMessage("10024")
|
|
|
// }
|
|
|
// logintoken, _ = GenerateAuthToken(mtoken.UID, mtoken.CompanyID)
|
|
|
// return logintoken, nil
|
|
|
// }
|
|
|
|
|
|
func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, error) {
|
|
|
var (
|
|
|
err error
|
...
|
...
|
@@ -239,7 +215,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
log.Error("更新用户数据失败:%s", err)
|
|
|
}
|
|
|
|
|
|
InitPermission(usercompanyid)
|
|
|
InitPermission(usercompanyid, userdata.Id)
|
|
|
return logintoken, err
|
|
|
}
|
|
|
|
...
|
...
|
@@ -392,22 +368,6 @@ func GetUserHasMenu(userid, companyid int64) ([]protocol.ResponseUserHasMenu, er |
|
|
return list, nil
|
|
|
}
|
|
|
|
|
|
//主管拥有全部的菜单
|
|
|
// func getAdminHasMenu() ([]protocol.PermissionItem, error) {
|
|
|
// const datasql string = `SELECT id,name,icon,parent_id,senior_status,sort,code
|
|
|
// FROM menu WHERE enabled=1 ORDER BY sort `
|
|
|
// var (
|
|
|
// list = make([]protocol.PermissionItem, 0)
|
|
|
// err error
|
|
|
// )
|
|
|
// err = utils.ExecuteQueryAll(&list, datasql)
|
|
|
// if err != nil {
|
|
|
// log.Error("EXECUTE SQL err:%s", err)
|
|
|
// return nil, protocol.NewErrWithMessage("1")
|
|
|
// }
|
|
|
// return list, nil
|
|
|
// }
|
|
|
|
|
|
func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, error) {
|
|
|
var (
|
|
|
err error
|
...
|
...
|
@@ -477,7 +437,7 @@ func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, err |
|
|
if err != nil {
|
|
|
log.Error("更新用户数据失败:%s", err)
|
|
|
}
|
|
|
InitPermission(usercompanyid)
|
|
|
InitPermission(usercompanyid, userdata.Id)
|
|
|
return logintoken, err
|
|
|
}
|
|
|
|
...
|
...
|
@@ -508,7 +468,7 @@ func SmsCodeCheck(phone string, code string) error { |
|
|
}
|
|
|
|
|
|
//InitPermission 登录时权限初始化
|
|
|
func InitPermission(usercompanyid int64) error {
|
|
|
func InitPermission(usercompanyid int64, usercompamyid int64) error {
|
|
|
var (
|
|
|
err error
|
|
|
permissionMap map[string]serverbac.PermissionOptionObject
|
...
|
...
|
@@ -518,7 +478,8 @@ func InitPermission(usercompanyid int64) error { |
|
|
log.Error("获取用户的权限失败")
|
|
|
return err
|
|
|
}
|
|
|
err = redisdata.SetUserPermission(permissionMap, usercompanyid)
|
|
|
|
|
|
err = redisdata.SetUserPermission(permissionMap, usercompamyid)
|
|
|
if err != nil {
|
|
|
log.Error("缓存用户权限失败:%s", err)
|
|
|
}
|
...
|
...
|
@@ -536,9 +497,18 @@ func ValidUserPermission(urlPath string, userid int64, companyid int64) bool { |
|
|
if !ok {
|
|
|
return true
|
|
|
}
|
|
|
companyinfo, err := models.GetCompanyById(companyid)
|
|
|
if err != nil {
|
|
|
log.Error("获取公司数据失败")
|
|
|
return false
|
|
|
}
|
|
|
if companyinfo.AdminId == userid {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
permissionObj, err = redisdata.GetUserPermission(userid, permissionbase.CodeName)
|
|
|
if err != nil {
|
|
|
log.Error("未取到权限数据")
|
|
|
log.Error("未取到权限数据 err:%s", err)
|
|
|
return false
|
|
|
}
|
|
|
ok = permissionObj.GetValidFunc(permissionbase.ActionName)
|
...
|
...
|
|