Commit 56c739ceb1276bd08effaaaa02869c3b0e46d1f1

Authored by jiangjiazhi
1 parent 06b224a1f3

commit

Showing 1 changed file with 27 additions and 22 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/session/strategy/LocalCacheSessionStrategy.java View file @ 56c739c
... ... @@ -26,7 +26,7 @@
26 26  
27 27 /**
28 28 * 本地session缓存策略
29   - * <p>
  29 + * <p/>
30 30 * Created by Administrator on 2016/6/2 0002.
31 31 */
32 32 public class LocalCacheSessionStrategy implements ISessionProvider {
33 33  
34 34  
... ... @@ -37,18 +37,18 @@
37 37  
38 38 private Map<String, LoginContext> localSessionCache = new ConcurrentHashMap<>();
39 39  
40   - public static Cache<String,LoginContext> cache = CacheBuilder.newBuilder()
  40 + public static Cache<String, LoginContext> cache = CacheBuilder.newBuilder()
41 41 .expireAfterAccess(6, TimeUnit.HOURS)
42 42 .build();
43 43  
44 44 @Override
45 45 public LoginContext checkSession(HttpServletRequest request, HttpServletResponse response, String token) {
46   - LoginContext loginContext = cache.getIfPresent(token);
47   - if(null==loginContext||!loginContext.isLogin()) {
  46 + LoginContext loginContext = cache.getIfPresent(token);
  47 + if (null == loginContext || !loginContext.isLogin()) {
48 48 throw new TokenException();
49 49 }
50 50 Users users = usersService.getUsers(loginContext.getId());
51   - if(null == users) {
  51 + if (null == users) {
52 52 throw new TokenException();
53 53 }
54 54 request.setAttribute("loginContext", loginContext);
55 55  
56 56  
57 57  
58 58  
59 59  
... ... @@ -66,35 +66,40 @@
66 66  
67 67 UsersQuery membersQuery = new UsersQuery();
68 68 membersQuery.setAccount(account);
69   - if(StringUtils.isNotEmpty(password)){
70   - membersQuery.setPwd(MD5Utils.md5(password).toUpperCase());
71   - }else{
72   - if(StringUtils.isNotEmpty(code)){
73   - throw new BusinessException(ErrorCodeConstants.BUSINESS_ERROR+"","该版本不支持手机号登录.");
74   - }else{
75   - throw new BusinessException(ErrorCodeConstants.BUSINESS_ERROR+"","密码不能为空.");
76   - }
  69 + if (StringUtils.isEmpty(password)) {
  70 + throw new BusinessException(ErrorCodeConstants.BUSINESS_ERROR + "", "密码不能为空.");
  71 + } else if (StringUtils.isNotEmpty(code)) {
  72 + throw new BusinessException(ErrorCodeConstants.BUSINESS_ERROR + "", "该版本不支持手机号登录.");
77 73 }
  74 +
78 75 membersQuery.setYn(YnEnums.YES.getId());
79 76 //本地版本忽略code没有短信验证码
80 77 List<Users> membersList = usersService.queryUsers(membersQuery);
81 78 LoginContext loginContext = new LoginContext();
82   - loginContext.setErrormsg("用户不存在.");
83   - loginContext.setErrorcode(4003);
84 79 if (CollectionUtils.isNotEmpty(membersList)) {
85 80 Integer userId = membersList.get(0).getId();
86   - loginContext.setId(userId);
87   - String token = preFix + TokenUtils.getToken(UUID.randomUUID().toString());
88   - loginContext.setToken(token);
89   - loginContext.setErrorcode(0);
90   - loginContext.setErrormsg("登录成功");
91   - cache.put(token, loginContext);
  81 + if(MD5Utils.md5(password).toUpperCase().equals(membersList.get(0).getPwd())){
  82 + loginContext.setId(userId);
  83 + String token = preFix + TokenUtils.getToken(UUID.randomUUID().toString());
  84 + loginContext.setToken(token);
  85 + loginContext.setErrorcode(0);
  86 + loginContext.setErrormsg("登录成功");
  87 + cache.put(token, loginContext);
  88 + }else{
  89 + loginContext.setErrormsg("密码错误.");
  90 + loginContext.setErrorcode(4003);
  91 + }
  92 + }else{
  93 + loginContext.setErrormsg("用户不存在.");
  94 + loginContext.setErrorcode(4003);
92 95 }
93 96 return loginContext;
94 97 }
95   - public static void main(String[] args){
  98 +
  99 + public static void main(String[] args) {
96 100 System.out.print(MD5Utils.md5("123456").toUpperCase());
97 101 }
  102 +
98 103 @Override
99 104 public LoginContext register(String userId, String phone, String account, String pwd) {
100 105 LoginContext loginContext = new LoginContext();