|
@@ -523,26 +523,40 @@ func (c *BaseAuthController) Prepare() {
|
|
|
tokenArr := strings.Split(tokenStr, "=")
|
|
|
token := tokenArr[1]
|
|
|
|
|
|
+ // 找不到session, 也直接切CookieValue中的用户登录
|
|
|
session, err := system.GetSysSessionByToken(token)
|
|
|
- if err != nil {
|
|
|
- if utils.IsErrNoRow(err) {
|
|
|
- c.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "Token 信息已变更:Token: " + token}, false, false)
|
|
|
+ //if err != nil {
|
|
|
+ // if utils.IsErrNoRow(err) {
|
|
|
+ // c.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "Token 信息已变更:Token: " + token}, false, false)
|
|
|
+ // c.StopRun()
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // c.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "获取用户信息异常,Eerr:" + err.Error()}, false, false)
|
|
|
+ // c.StopRun()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //if session == nil {
|
|
|
+ // c.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "sesson is empty "}, false, false)
|
|
|
+ // c.StopRun()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ if err != nil || session == nil {
|
|
|
+ newLogin, e := services.UserLoginChange(cookieVal)
|
|
|
+ if e != nil {
|
|
|
+ c.JSON(models.BaseResponse{Ret: 408, Msg: "重登录失败,请稍后重试!", ErrMsg: fmt.Sprint(e)}, false, false)
|
|
|
c.StopRun()
|
|
|
return
|
|
|
}
|
|
|
- c.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "获取用户信息异常,Eerr:" + err.Error()}, false, false)
|
|
|
- c.StopRun()
|
|
|
- return
|
|
|
- }
|
|
|
- if session == nil {
|
|
|
- c.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "sesson is empty "}, false, false)
|
|
|
+ c.JSON(models.BaseResponse{Ret: models.BaseRespReLoginErr, Msg: "用户切换,请刷新页面", ErrMsg: "user exchanged", Data: newLogin}, false, false)
|
|
|
c.StopRun()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // CookieVal不匹配、token验证失败、token过期,那么以cookieVal的用户去登录并返回4014
|
|
|
+ // CookieVal不匹配、token验证失败、session以及redis中的token过期,那么以cookieVal的用户去登录并返回4014
|
|
|
account := utils.MD5(session.UserName)
|
|
|
- if session.UserName != cookieVal || !utils.CheckToken(account, token) || time.Now().After(session.ExpiredTime) {
|
|
|
+ loginKey := fmt.Sprint(utils.CACHE_ACCESS_TOKEN_LOGIN, session.Id)
|
|
|
+ loginCache, _ := utils.Rc.RedisString(loginKey)
|
|
|
+ if session.UserName != cookieVal || !utils.CheckToken(account, token) || time.Now().After(session.ExpiredTime) || (session.IsRemember != 1 && loginCache == ``) {
|
|
|
newLogin, e := services.UserLoginChange(cookieVal)
|
|
|
if e != nil {
|
|
|
c.JSON(models.BaseResponse{Ret: 408, Msg: "重登录失败,请稍后重试!", ErrMsg: fmt.Sprint(e)}, false, false)
|