作者 唐旭辉

bug fix

... ... @@ -6,6 +6,7 @@ import (
"oppmg/common/log"
"oppmg/protocol"
serveauth "oppmg/services/auth"
"oppmg/services/ucenter"
"oppmg/storage/redisdata"
"strconv"
"time"
... ... @@ -101,15 +102,30 @@ func (c *AuthController) LoginSms() {
msg = protocol.BadRequestParam("10021")
return
}
logintoken, err := serveauth.LoginAuthBySmsCode(param.Account, param.Code)
err = serveauth.ResetLoginToken(logintoken)
var uclientReturn *ucenter.ResponseLoginSms
uclientReturn, err := ucenter.RequestUCenterLoginSms(param.Account, param.Code)
if err != nil {
log.Error("token 信息记录数据库失败")
if uclientReturn != nil {
msg = &protocol.ResponseMessage{
Errno: -1,
Errmsg: uclientReturn.Msg,
Data: protocol.NullData,
}
} else {
msg = protocol.NewMessage("10028")
}
return
}
err = serveauth.ResetLoginTokenRedis(logintoken)
if err != nil {
log.Error("token 信息记录redis失败")
logintoken, err := serveauth.LoginAuthBySmsCode(uclientReturn)
if err == nil {
err = serveauth.ResetLoginToken(logintoken)
if err != nil {
log.Error("token 信息记录数据库失败")
}
err = serveauth.ResetLoginTokenRedis(logintoken)
if err != nil {
log.Error("token 信息记录redis失败")
}
}
data := protocol.ResponseLogin{
Access: logintoken,
... ... @@ -229,10 +245,12 @@ func (c *AuthController) Me() {
if err != nil {
log.Error("获取用户的公司失败")
}
permissionMap := serveauth.GetUserMenuPermission(userid)
data := map[string]interface{}{
"user": userinfo,
"menus": menus,
"companys": companys,
"user": userinfo,
"menus": menus,
"companys": companys,
"permission": permissionMap,
}
msg = protocol.NewReturnResponse(data, nil)
return
... ...
... ... @@ -33,7 +33,7 @@ var errmessge ErrorMap = map[string]string{
"10025": "该账号已在其他地方登录",
"10026": "验证码校验失败",
"10027": "无操作权限",
"10028": "验证码错误",
"10028": "请输入正确的验证码",
"10029": "获取验证码失败",
"10080": "无操作权限",
... ...
... ... @@ -143,7 +143,8 @@ func ChangeLoginToken(userid, companyid int64) (protocol.LoginAuthToken, error)
return logintoken, nil
}
func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, error) {
func LoginAuthByUCenter(account, password string) (
protocol.LoginAuthToken, error) {
var (
err error
logintoken protocol.LoginAuthToken
... ... @@ -368,7 +369,29 @@ func GetUserHasMenu(userid, companyid int64) ([]protocol.ResponseUserHasMenu, er
return list, nil
}
func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, error) {
func GetUserMenuPermission(userid int64) map[string]serverbac.PermissionOptionObject {
var (
permissionMap = make(map[string]serverbac.PermissionOptionObject)
err error
)
permissionMap, err = redisdata.GetUserPermissionAll(userid)
if err != nil {
log.Error("获取权限数据失败 :%s", err)
}
if v, ok := permissionMap[serverbac.M_SYSTEM_OPPORTUNITY]; ok {
if vv, ok := v.(*serverbac.OptionOpportunity); ok {
vv.CheckMap = nil
vv.CheckOption = nil
permissionMap[serverbac.M_SYSTEM_OPPORTUNITY] = vv
}
}
return permissionMap
}
func LoginAuthBySmsCode(uclientReturn *ucenter.ResponseLoginSms) (
protocol.LoginAuthToken, error) {
var (
err error
logintoken protocol.LoginAuthToken
... ... @@ -377,11 +400,7 @@ func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, err
usercompanyid int64
userdata *models.User
)
var uclientReturn *ucenter.ResponseLoginSms
uclientReturn, err = ucenter.RequestUCenterLoginSms(phone, code)
if err != nil {
return logintoken, protocol.NewErrWithMessage("10028")
}
userdata, err = models.GetUserByUCenter(uclientReturn.Data.Cuid)
if err != nil {
log.Debug("GetUserByUCenter(%s) err:%s", uclientReturn.Data.Cuid, err)
... ... @@ -468,22 +487,22 @@ func SmsCodeCheck(phone string, code string) error {
}
//InitPermission 登录时权限初始化
func InitPermission(usercompanyid int64, usercompamyid int64) error {
func InitPermission(usercompanyid int64, usercompamyid int64) (map[string]serverbac.PermissionOptionObject, error) {
var (
err error
permissionMap map[string]serverbac.PermissionOptionObject
permissionMap = make(map[string]serverbac.PermissionOptionObject)
)
permissionMap, err = serverbac.GetUserPermission(usercompanyid)
if err != nil {
log.Error("获取用户的权限失败")
return err
return permissionMap, err
}
err = redisdata.SetUserPermission(permissionMap, usercompamyid)
if err != nil {
log.Error("缓存用户权限失败:%s", err)
}
return nil
return permissionMap, nil
}
func ValidUserPermission(urlPath string, userid int64, companyid int64) bool {
... ...
... ... @@ -228,7 +228,7 @@ func UpdateSetOpportunity(param OptionOpportunity, roleid int64, companyid int64
//机会管理高级设置
func GetSetOpportunity(roleid int64, companyid int64) (*OptionOpportunity, error) {
setting := &OptionOpportunity{
CheckOption: CheckOpp{
CheckOption: &CheckOpp{
Departments: []CheckDeparment{},
},
}
... ...
... ... @@ -96,7 +96,7 @@ type CheckOpp struct {
type OptionOpportunity struct {
Check int `json:"check"`
CheckMap map[int]int `json:"check_map,omitempty"`
CheckOption CheckOpp `json:"check_option"`
CheckOption *CheckOpp `json:"check_option,omitempty"`
EditSorce int `json:"edit_sorce"`
EditPublicStatus int `json:"edit_public_status"`
CloseChance int `json:"close_chance"`
... ... @@ -125,7 +125,7 @@ func NewOptionOpportunity() PermissionOptionObject {
return &OptionOpportunity{
Check: OpportunityCheckLv4,
CheckMap: make(map[int]int),
CheckOption: CheckOpp{
CheckOption: &CheckOpp{
Departments: []CheckDeparment{},
},
}
... ...
... ... @@ -109,7 +109,7 @@ func RequestUCenterLoginSms(phone string, captcha string) (*ResponseLoginSms, er
return nil, protocol.NewErrWithMessage("1")
}
if !(ucenterReturn.Code == ResponseCode0) {
return nil, protocol.NewErrWithMessage("10052")
return &ucenterReturn, protocol.NewErrWithMessage("10052")
}
return &ucenterReturn, nil
}
... ... @@ -132,7 +132,7 @@ func RequestUCenterSmsCodeCheck(phone string, captcha string) (*ResponseSmsCodeC
return nil, protocol.NewErrWithMessage("1")
}
if !(ucenterReturn.Code == ResponseCode0) {
return nil, protocol.NewErrWithMessage("10026")
return &ucenterReturn, protocol.NewErrWithMessage("10026")
}
return &ucenterReturn, nil
}
... ...
... ... @@ -144,3 +144,15 @@ func ExistUserPermission(userid int64) bool {
}
return false
}
func GetUserPermissionAll(userid int64) (map[string]rbac.PermissionOptionObject, error) {
key := GetKeyUserPermission(userid)
client := redis.GetRedis()
str, err := client.Get(key).Result()
if err != nil {
return nil, err
}
permissionObj := make(map[string]rbac.PermissionOptionObject)
err = json.Unmarshal([]byte(str), &permissionObj)
return permissionObj, err
}
... ...