Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 Client Login 的问题 #8

Closed
46094570 opened this issue Jan 2, 2019 · 15 comments
Closed

关于 Client Login 的问题 #8

46094570 opened this issue Jan 2, 2019 · 15 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@46094570
Copy link

46094570 commented Jan 2, 2019

在 client login 的时候,userLogin 方法会向 Route 发送验证登录信息。让人疑惑的事,Route 去 Redis 中检查这个 client 是否存在,在接下来的 if 判断语句中,如果这个 client 不存在,返回的居然是已登录 - -! 这里非常不明白,是个 bug 吗

@crossoverJie crossoverJie added the question Further information is requested label Jan 2, 2019
@crossoverJie
Copy link
Owner

没太懂什么意思。

public boolean login(LoginReqVO loginReqVO) throws Exception {
//再去Redis里查询
String key = ACCOUNT_PREFIX + loginReqVO.getUserId();
String userName = redisTemplate.opsForValue().get(key);
if (null == userName) {
return false;
}
if (!userName.equals(loginReqVO.getUserName())) {
return false;
}
//登录成功,保存登录状态
boolean status = userInfoCacheService.saveAndCheckUserLoginStatus(loginReqVO.getUserId());
if (status == false){
//重复登录
return false;
}
return true;
}

不存在是返回的 false

@46094570
Copy link
Author

46094570 commented Jan 3, 2019

没太懂什么意思。

cim/cim-forward-route/src/main/java/com/crossoverjie/cim/route/service/impl/AccountServiceRedisImpl.java

Lines 72 to 92 in b6608ad

public boolean login(LoginReqVO loginReqVO) throws Exception {
//再去Redis里查询
String key = ACCOUNT_PREFIX + loginReqVO.getUserId();
String userName = redisTemplate.opsForValue().get(key);
if (null == userName) {
return false;
}

 if (!userName.equals(loginReqVO.getUserName())) { 
     return false; 
 } 

 //登录成功,保存登录状态 
 boolean status = userInfoCacheService.saveAndCheckUserLoginStatus(loginReqVO.getUserId()); 
 if (status == false){ 
     //重复登录 
     return false; 
 } 

 return true; 

}
不存在是返回的 false

你看这里啊,用前缀+userId去查询redis,如果从来没登录过(一次都没有,或者第一次启动系统),那就是空。然后在com.crossoverjie.cim.route.controller.RouteController#login 这个方法中,if(login) 才执行保存路由信息,不然的话就是返回说已经重复登录了。这种情况下逻辑不是有点问题么,我从来没有登录过,为何结果要返回给我说账号已登录?

@crossoverJie
Copy link
Owner

@46094570

我懂你意思了,就是 userID+userName 不匹配的话还是返回的重复登录吧?

这是因为之前没考虑重复登录的事就只用了 boolean 来保存状态,所以只有两种值。

后面优化为一个枚举提示登录信息不匹配即可。

@crossoverJie crossoverJie added the enhancement New feature or request label Jan 3, 2019
@xuegangliu
Copy link

  1. 第一次登录redis里没有用户,应该登录成功
  2. 第二次登录在redis查询出用户应该显示重复登录吧

@huxudong
Copy link

huxudong commented Jan 3, 2019

我也遇到这个问题了,启动client提示用户不存在。

@crossoverJie
Copy link
Owner

@xuegangliu @huxudong

目前登录失败只会提示 账号重复登录,请退出一个账号! 这个吧;有两种情况:

  • 登录信息不匹配。
  • 真的是重复登录。

不管是哪种,肯定都是不能登录地。

下一版本会优化这个提示。

@huxudong
Copy link

huxudong commented Jan 3, 2019

@xuegangliu @huxudong

目前登录失败只会提示 账号重复登录,请退出一个账号! 这个吧;有两种情况:

  • 登录信息不匹配。
  • 真的是重复登录。

不管是哪种,肯定都是不能登录地。

下一版本会优化这个提示。

我说错了,应该是重复登录,如图
image

@huxudong
Copy link

huxudong commented Jan 3, 2019

我感觉大家的困惑是,如何才能登录呢?

@crossoverJie
Copy link
Owner

@huxudong 你用的是我搭的公网服务嘛?

演示环境里目前没有 zhangsan1 这个账号,只是提示有问题

我感觉大家的困惑是,如何才能登录呢?

userId + userNameRedis 能匹配并且没有其他人先登录即可登录;具体请看详细设计:

https://crossoverjie.top/2019/01/02/netty/cim01-started/#%E7%99%BB%E5%BD%95

@huxudong
Copy link

huxudong commented Jan 3, 2019

@huxudong 你用的是我搭的公网服务嘛?

演示环境里目前没有 zhangsan1 这个账号,只是提示有问题

我感觉大家的困惑是,如何才能登录呢?

userId + userNameRedis 能匹配并且没有其他人先登录即可登录;具体请看详细设计:

https://crossoverjie.top/2019/01/02/netty/cim01-started/#%E7%99%BB%E5%BD%95

我用的自己的zk、redis

@crossoverJie
Copy link
Owner

我用的自己的zk、redis

那就查看自己的 Redis 里是否有这个用户,和你的 userID+userName 是否匹配(ps:登录的前提是要注册)。

userId + userNameRedis 能匹配并且没有其他人先登录即可登录;

@huxudong
Copy link

huxudong commented Jan 3, 2019

我用的自己的zk、redis

那就查看自己的 Redis 里是否有这个用户,和你的 userID+userName 是否匹配(ps:登录的前提是要注册)。

userId + userNameRedis 能匹配并且没有其他人先登录即可登录;

@crossoverJie

ok了,谢谢,我用postman注册了一下,然后配置到client,启动了一下。

@crossoverJie
Copy link
Owner

@huxudong

这种小问题用 issue 不太好,可以加我微信 Y2h5Y2pq(base64) 我拉你进内测群,方便沟通。

@crossoverJie crossoverJie self-assigned this Jan 3, 2019
@xiaozi0lei
Copy link

不知道我这个文档是否能解决大家的问题,其实很多人应该都是本地跑环境,可能存在redis没有账号缓存,导致不能登录,如图:
image
可以参考一下这个 PR #11 会有点帮助,我本地跑起来了

@crossoverJie crossoverJie mentioned this issue Jan 11, 2019
@crossoverJie
Copy link
Owner

fixed.

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants