|
|
@@ -238,6 +238,20 @@ func buildRedisLoginInfo(loginaccount accountModel.Loginaccount, addr string, gr
|
|
|
|
|
|
// RestoreLoginWithToken 通过Token检验恢复登录状态失败
|
|
|
func RestoreLoginWithToken(loginID int, group int, token string) (err error) {
|
|
|
+ // 先判断Clients中是否有对应的对像
|
|
|
+ if client.Clients != nil {
|
|
|
+ targetKeys := make([]int, 0)
|
|
|
+ for key, item := range client.Clients {
|
|
|
+ if item.LoginID == strconv.Itoa(loginID) && item.Group == strconv.Itoa(group) {
|
|
|
+ targetKeys = append(targetKeys, key)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(targetKeys) > 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 没有的话重新创建一个
|
|
|
// 从Redis获取登录信息
|
|
|
j := utils.NewJWT()
|
|
|
loginMap, err := j.GetRedisLogin(loginID, group)
|
|
|
@@ -269,17 +283,6 @@ func RestoreLoginWithToken(loginID int, group int, token string) (err error) {
|
|
|
global.M2A_LOG.Error("Token检验恢复登录状态失败", zap.Error(err))
|
|
|
return
|
|
|
}
|
|
|
- // 这里应该按loginid和group把之前的client删除掉
|
|
|
- // delete(client.Clients, s)
|
|
|
- targetKeys := make([]int, 0)
|
|
|
- for key, item := range client.Clients {
|
|
|
- if item.LoginID == loginLogin.LoginID && item.Group == loginLogin.Group {
|
|
|
- targetKeys = append(targetKeys, key)
|
|
|
- }
|
|
|
- }
|
|
|
- for _, k := range targetKeys {
|
|
|
- delete(client.Clients, k)
|
|
|
- }
|
|
|
client.Clients[s] = &client.Client{LoginRedis: loginLogin}
|
|
|
|
|
|
return
|
|
|
@@ -298,7 +301,6 @@ func GetClientsByAccountID(accountID uint64) (clients []*client.Client, err erro
|
|
|
WHERE a.accountid = %v
|
|
|
`, accountID)
|
|
|
if err = global.M2A_DB.SQL(sql).Find(&loginIds); err != nil {
|
|
|
-
|
|
|
global.M2A_LOG.Info("获取LoginID失败", zap.Error(err))
|
|
|
return
|
|
|
} else {
|