正在显示
7 个修改的文件
包含
76 行增加
和
27 行删除
@@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
6 | "oppmg/common/log" | 6 | "oppmg/common/log" |
7 | "oppmg/protocol" | 7 | "oppmg/protocol" |
8 | serveauth "oppmg/services/auth" | 8 | serveauth "oppmg/services/auth" |
9 | + "oppmg/services/ucenter" | ||
9 | "oppmg/storage/redisdata" | 10 | "oppmg/storage/redisdata" |
10 | "strconv" | 11 | "strconv" |
11 | "time" | 12 | "time" |
@@ -101,15 +102,30 @@ func (c *AuthController) LoginSms() { | @@ -101,15 +102,30 @@ func (c *AuthController) LoginSms() { | ||
101 | msg = protocol.BadRequestParam("10021") | 102 | msg = protocol.BadRequestParam("10021") |
102 | return | 103 | return |
103 | } | 104 | } |
104 | - | ||
105 | - logintoken, err := serveauth.LoginAuthBySmsCode(param.Account, param.Code) | ||
106 | - err = serveauth.ResetLoginToken(logintoken) | 105 | + var uclientReturn *ucenter.ResponseLoginSms |
106 | + uclientReturn, err := ucenter.RequestUCenterLoginSms(param.Account, param.Code) | ||
107 | if err != nil { | 107 | if err != nil { |
108 | - log.Error("token 信息记录数据库失败") | 108 | + if uclientReturn != nil { |
109 | + msg = &protocol.ResponseMessage{ | ||
110 | + Errno: -1, | ||
111 | + Errmsg: uclientReturn.Msg, | ||
112 | + Data: protocol.NullData, | ||
113 | + } | ||
114 | + } else { | ||
115 | + msg = protocol.NewMessage("10028") | ||
116 | + } | ||
117 | + return | ||
109 | } | 118 | } |
110 | - err = serveauth.ResetLoginTokenRedis(logintoken) | ||
111 | - if err != nil { | ||
112 | - log.Error("token 信息记录redis失败") | 119 | + logintoken, err := serveauth.LoginAuthBySmsCode(uclientReturn) |
120 | + if err == nil { | ||
121 | + err = serveauth.ResetLoginToken(logintoken) | ||
122 | + if err != nil { | ||
123 | + log.Error("token 信息记录数据库失败") | ||
124 | + } | ||
125 | + err = serveauth.ResetLoginTokenRedis(logintoken) | ||
126 | + if err != nil { | ||
127 | + log.Error("token 信息记录redis失败") | ||
128 | + } | ||
113 | } | 129 | } |
114 | data := protocol.ResponseLogin{ | 130 | data := protocol.ResponseLogin{ |
115 | Access: logintoken, | 131 | Access: logintoken, |
@@ -229,10 +245,12 @@ func (c *AuthController) Me() { | @@ -229,10 +245,12 @@ func (c *AuthController) Me() { | ||
229 | if err != nil { | 245 | if err != nil { |
230 | log.Error("获取用户的公司失败") | 246 | log.Error("获取用户的公司失败") |
231 | } | 247 | } |
248 | + permissionMap := serveauth.GetUserMenuPermission(userid) | ||
232 | data := map[string]interface{}{ | 249 | data := map[string]interface{}{ |
233 | - "user": userinfo, | ||
234 | - "menus": menus, | ||
235 | - "companys": companys, | 250 | + "user": userinfo, |
251 | + "menus": menus, | ||
252 | + "companys": companys, | ||
253 | + "permission": permissionMap, | ||
236 | } | 254 | } |
237 | msg = protocol.NewReturnResponse(data, nil) | 255 | msg = protocol.NewReturnResponse(data, nil) |
238 | return | 256 | return |
@@ -33,7 +33,7 @@ var errmessge ErrorMap = map[string]string{ | @@ -33,7 +33,7 @@ var errmessge ErrorMap = map[string]string{ | ||
33 | "10025": "该账号已在其他地方登录", | 33 | "10025": "该账号已在其他地方登录", |
34 | "10026": "验证码校验失败", | 34 | "10026": "验证码校验失败", |
35 | "10027": "无操作权限", | 35 | "10027": "无操作权限", |
36 | - "10028": "验证码错误", | 36 | + "10028": "请输入正确的验证码", |
37 | "10029": "获取验证码失败", | 37 | "10029": "获取验证码失败", |
38 | "10080": "无操作权限", | 38 | "10080": "无操作权限", |
39 | 39 |
@@ -143,7 +143,8 @@ func ChangeLoginToken(userid, companyid int64) (protocol.LoginAuthToken, error) | @@ -143,7 +143,8 @@ func ChangeLoginToken(userid, companyid int64) (protocol.LoginAuthToken, error) | ||
143 | return logintoken, nil | 143 | return logintoken, nil |
144 | } | 144 | } |
145 | 145 | ||
146 | -func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, error) { | 146 | +func LoginAuthByUCenter(account, password string) ( |
147 | + protocol.LoginAuthToken, error) { | ||
147 | var ( | 148 | var ( |
148 | err error | 149 | err error |
149 | logintoken protocol.LoginAuthToken | 150 | logintoken protocol.LoginAuthToken |
@@ -368,7 +369,29 @@ func GetUserHasMenu(userid, companyid int64) ([]protocol.ResponseUserHasMenu, er | @@ -368,7 +369,29 @@ func GetUserHasMenu(userid, companyid int64) ([]protocol.ResponseUserHasMenu, er | ||
368 | return list, nil | 369 | return list, nil |
369 | } | 370 | } |
370 | 371 | ||
371 | -func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, error) { | 372 | +func GetUserMenuPermission(userid int64) map[string]serverbac.PermissionOptionObject { |
373 | + var ( | ||
374 | + permissionMap = make(map[string]serverbac.PermissionOptionObject) | ||
375 | + err error | ||
376 | + ) | ||
377 | + permissionMap, err = redisdata.GetUserPermissionAll(userid) | ||
378 | + if err != nil { | ||
379 | + log.Error("获取权限数据失败 :%s", err) | ||
380 | + } | ||
381 | + | ||
382 | + if v, ok := permissionMap[serverbac.M_SYSTEM_OPPORTUNITY]; ok { | ||
383 | + if vv, ok := v.(*serverbac.OptionOpportunity); ok { | ||
384 | + vv.CheckMap = nil | ||
385 | + vv.CheckOption = nil | ||
386 | + permissionMap[serverbac.M_SYSTEM_OPPORTUNITY] = vv | ||
387 | + } | ||
388 | + } | ||
389 | + | ||
390 | + return permissionMap | ||
391 | +} | ||
392 | + | ||
393 | +func LoginAuthBySmsCode(uclientReturn *ucenter.ResponseLoginSms) ( | ||
394 | + protocol.LoginAuthToken, error) { | ||
372 | var ( | 395 | var ( |
373 | err error | 396 | err error |
374 | logintoken protocol.LoginAuthToken | 397 | logintoken protocol.LoginAuthToken |
@@ -377,11 +400,7 @@ func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, err | @@ -377,11 +400,7 @@ func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, err | ||
377 | usercompanyid int64 | 400 | usercompanyid int64 |
378 | userdata *models.User | 401 | userdata *models.User |
379 | ) | 402 | ) |
380 | - var uclientReturn *ucenter.ResponseLoginSms | ||
381 | - uclientReturn, err = ucenter.RequestUCenterLoginSms(phone, code) | ||
382 | - if err != nil { | ||
383 | - return logintoken, protocol.NewErrWithMessage("10028") | ||
384 | - } | 403 | + |
385 | userdata, err = models.GetUserByUCenter(uclientReturn.Data.Cuid) | 404 | userdata, err = models.GetUserByUCenter(uclientReturn.Data.Cuid) |
386 | if err != nil { | 405 | if err != nil { |
387 | log.Debug("GetUserByUCenter(%s) err:%s", uclientReturn.Data.Cuid, err) | 406 | log.Debug("GetUserByUCenter(%s) err:%s", uclientReturn.Data.Cuid, err) |
@@ -468,22 +487,22 @@ func SmsCodeCheck(phone string, code string) error { | @@ -468,22 +487,22 @@ func SmsCodeCheck(phone string, code string) error { | ||
468 | } | 487 | } |
469 | 488 | ||
470 | //InitPermission 登录时权限初始化 | 489 | //InitPermission 登录时权限初始化 |
471 | -func InitPermission(usercompanyid int64, usercompamyid int64) error { | 490 | +func InitPermission(usercompanyid int64, usercompamyid int64) (map[string]serverbac.PermissionOptionObject, error) { |
472 | var ( | 491 | var ( |
473 | err error | 492 | err error |
474 | - permissionMap map[string]serverbac.PermissionOptionObject | 493 | + permissionMap = make(map[string]serverbac.PermissionOptionObject) |
475 | ) | 494 | ) |
476 | permissionMap, err = serverbac.GetUserPermission(usercompanyid) | 495 | permissionMap, err = serverbac.GetUserPermission(usercompanyid) |
477 | if err != nil { | 496 | if err != nil { |
478 | log.Error("获取用户的权限失败") | 497 | log.Error("获取用户的权限失败") |
479 | - return err | 498 | + return permissionMap, err |
480 | } | 499 | } |
481 | 500 | ||
482 | err = redisdata.SetUserPermission(permissionMap, usercompamyid) | 501 | err = redisdata.SetUserPermission(permissionMap, usercompamyid) |
483 | if err != nil { | 502 | if err != nil { |
484 | log.Error("缓存用户权限失败:%s", err) | 503 | log.Error("缓存用户权限失败:%s", err) |
485 | } | 504 | } |
486 | - return nil | 505 | + return permissionMap, nil |
487 | } | 506 | } |
488 | 507 | ||
489 | func ValidUserPermission(urlPath string, userid int64, companyid int64) bool { | 508 | func ValidUserPermission(urlPath string, userid int64, companyid int64) bool { |
@@ -228,7 +228,7 @@ func UpdateSetOpportunity(param OptionOpportunity, roleid int64, companyid int64 | @@ -228,7 +228,7 @@ func UpdateSetOpportunity(param OptionOpportunity, roleid int64, companyid int64 | ||
228 | //机会管理高级设置 | 228 | //机会管理高级设置 |
229 | func GetSetOpportunity(roleid int64, companyid int64) (*OptionOpportunity, error) { | 229 | func GetSetOpportunity(roleid int64, companyid int64) (*OptionOpportunity, error) { |
230 | setting := &OptionOpportunity{ | 230 | setting := &OptionOpportunity{ |
231 | - CheckOption: CheckOpp{ | 231 | + CheckOption: &CheckOpp{ |
232 | Departments: []CheckDeparment{}, | 232 | Departments: []CheckDeparment{}, |
233 | }, | 233 | }, |
234 | } | 234 | } |
@@ -96,7 +96,7 @@ type CheckOpp struct { | @@ -96,7 +96,7 @@ type CheckOpp struct { | ||
96 | type OptionOpportunity struct { | 96 | type OptionOpportunity struct { |
97 | Check int `json:"check"` | 97 | Check int `json:"check"` |
98 | CheckMap map[int]int `json:"check_map,omitempty"` | 98 | CheckMap map[int]int `json:"check_map,omitempty"` |
99 | - CheckOption CheckOpp `json:"check_option"` | 99 | + CheckOption *CheckOpp `json:"check_option,omitempty"` |
100 | EditSorce int `json:"edit_sorce"` | 100 | EditSorce int `json:"edit_sorce"` |
101 | EditPublicStatus int `json:"edit_public_status"` | 101 | EditPublicStatus int `json:"edit_public_status"` |
102 | CloseChance int `json:"close_chance"` | 102 | CloseChance int `json:"close_chance"` |
@@ -125,7 +125,7 @@ func NewOptionOpportunity() PermissionOptionObject { | @@ -125,7 +125,7 @@ func NewOptionOpportunity() PermissionOptionObject { | ||
125 | return &OptionOpportunity{ | 125 | return &OptionOpportunity{ |
126 | Check: OpportunityCheckLv4, | 126 | Check: OpportunityCheckLv4, |
127 | CheckMap: make(map[int]int), | 127 | CheckMap: make(map[int]int), |
128 | - CheckOption: CheckOpp{ | 128 | + CheckOption: &CheckOpp{ |
129 | Departments: []CheckDeparment{}, | 129 | Departments: []CheckDeparment{}, |
130 | }, | 130 | }, |
131 | } | 131 | } |
@@ -109,7 +109,7 @@ func RequestUCenterLoginSms(phone string, captcha string) (*ResponseLoginSms, er | @@ -109,7 +109,7 @@ func RequestUCenterLoginSms(phone string, captcha string) (*ResponseLoginSms, er | ||
109 | return nil, protocol.NewErrWithMessage("1") | 109 | return nil, protocol.NewErrWithMessage("1") |
110 | } | 110 | } |
111 | if !(ucenterReturn.Code == ResponseCode0) { | 111 | if !(ucenterReturn.Code == ResponseCode0) { |
112 | - return nil, protocol.NewErrWithMessage("10052") | 112 | + return &ucenterReturn, protocol.NewErrWithMessage("10052") |
113 | } | 113 | } |
114 | return &ucenterReturn, nil | 114 | return &ucenterReturn, nil |
115 | } | 115 | } |
@@ -132,7 +132,7 @@ func RequestUCenterSmsCodeCheck(phone string, captcha string) (*ResponseSmsCodeC | @@ -132,7 +132,7 @@ func RequestUCenterSmsCodeCheck(phone string, captcha string) (*ResponseSmsCodeC | ||
132 | return nil, protocol.NewErrWithMessage("1") | 132 | return nil, protocol.NewErrWithMessage("1") |
133 | } | 133 | } |
134 | if !(ucenterReturn.Code == ResponseCode0) { | 134 | if !(ucenterReturn.Code == ResponseCode0) { |
135 | - return nil, protocol.NewErrWithMessage("10026") | 135 | + return &ucenterReturn, protocol.NewErrWithMessage("10026") |
136 | } | 136 | } |
137 | return &ucenterReturn, nil | 137 | return &ucenterReturn, nil |
138 | } | 138 | } |
@@ -144,3 +144,15 @@ func ExistUserPermission(userid int64) bool { | @@ -144,3 +144,15 @@ func ExistUserPermission(userid int64) bool { | ||
144 | } | 144 | } |
145 | return false | 145 | return false |
146 | } | 146 | } |
147 | + | ||
148 | +func GetUserPermissionAll(userid int64) (map[string]rbac.PermissionOptionObject, error) { | ||
149 | + key := GetKeyUserPermission(userid) | ||
150 | + client := redis.GetRedis() | ||
151 | + str, err := client.Get(key).Result() | ||
152 | + if err != nil { | ||
153 | + return nil, err | ||
154 | + } | ||
155 | + permissionObj := make(map[string]rbac.PermissionOptionObject) | ||
156 | + err = json.Unmarshal([]byte(str), &permissionObj) | ||
157 | + return permissionObj, err | ||
158 | +} |
-
请 注册 或 登录 后发表评论