From a496c7b643bf5a4fb2efc93c911e28d425494006 Mon Sep 17 00:00:00 2001 From: yangjie <1179743470@qq.com> Date: Fri, 4 Jun 2021 11:52:59 +0800 Subject: [PATCH] user id --- src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java | 6 +++++- .../java/com/yipin/liuwanr/service/UserInfoService.java | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java b/src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java index 414a255..5f53dca 100644 --- a/src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java +++ b/src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java @@ -36,7 +36,11 @@ public class AuthInterceptor implements HandlerInterceptor { ValueOperations ops = stringRedisTemplate.opsForValue(); Object loginStatus = ops.get(token); - + //userid + String userId = request.getParameter("userId"); + if (!StringUtils.isEmpty(userId)){ + return userId.equals(ops.get(token)); + } if( Objects.isNull(loginStatus)){ response.getWriter().print("1");//token错误 diff --git a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java index a98b568..12160c9 100644 --- a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java +++ b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java @@ -441,7 +441,7 @@ public class UserInfoService { //鉴权,登录后将信息存入redis ValueOperations redis = stringRedisTemplate.opsForValue(); String loginToken = UUID.randomUUID().toString(); - redis.set(loginToken,user.getUserName(),2, TimeUnit.HOURS); + redis.set(loginToken,user.getUserId().toString(),2, TimeUnit.HOURS); obj.put("loginToken",loginToken); resp.put("retcode", 200); @@ -553,7 +553,7 @@ public class UserInfoService { //鉴权,登录后将信息存入redis String loginToken = UUID.randomUUID().toString(); - redis.set(loginToken,user.getUserName(),2, TimeUnit.HOURS); + redis.set(loginToken,user.getUserId().toString(),2, TimeUnit.HOURS); user.setLoginToken(loginToken); resp.put("retvalue",user);