Commit 39d5bad9 authored by m1991's avatar m1991

登录模块——用户退出功能修复

parent fcd5b3de
...@@ -109,7 +109,7 @@ public class Constants { ...@@ -109,7 +109,7 @@ public class Constants {
/** /**
* token相关 * token相关
*/ */
public final static String PREFIX_TOKEN = "token:"; public final static String PREFIX_TOKEN = "token";
} }
} }
...@@ -27,9 +27,9 @@ public class RedisKeyUtils { ...@@ -27,9 +27,9 @@ public class RedisKeyUtils {
*/ */
public static String formatKeyWithPrefix(String ... args){ public static String formatKeyWithPrefix(String ... args){
if (args != null && args.length > 0){ if (args != null && args.length > 0){
StringBuilder key = new StringBuilder(Constants.Redis.PREFIX).append(Constants.Connnector.UNDERLINE); StringBuilder key = new StringBuilder(Constants.Redis.PREFIX).append(Constants.Connnector.COLON);
for (String s: args){ for (String s: args){
key.append(s).append(Constants.Connnector.UNDERLINE); key.append(s).append(Constants.Connnector.COLON);
} }
return key.toString(); return key.toString();
} }
......
...@@ -331,9 +331,9 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U ...@@ -331,9 +331,9 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
@Override @Override
public int logout(String token) { public int logout(String token) {
int succ = 0; int succ = 0;
String key = RedisKeyUtils.formatKeyWithPrefix(token); // String key = RedisKeyUtils.formatKeyWithPrefix(token);
redisUtils.delete(key); redisUtils.delete(token);
if(redisUtils.getValue(key) == null){ if(redisUtils.getValue(token) == null){
succ = 1; succ = 1;
} }
return succ; return succ;
......
...@@ -193,19 +193,19 @@ public class LoginController { ...@@ -193,19 +193,19 @@ public class LoginController {
/** /**
* 退出登录 * 退出登录
* * @param
* @param token
* @return * @return
*/ */
@ApiOperation(value = "退出登录", produces = "application/json", notes = "退出登录") @ApiOperation(value = "退出登录", produces = "application/json", notes = "退出登录")
@ApiImplicitParam(paramType = "header", name = "token", value = "用户token", required = true, dataType = "String") @ApiImplicitParam(paramType = "header", name = "token", value = "用户token", required = true, dataType = "String")
@PostMapping("/logout") @PostMapping("/logout")
public Result logout(String token) { public Result logout(HttpServletRequest request) {
log.info("退出登录"); log.info("退出登录");
Result result = ResultUtils.returnFail(); Result result = ResultUtils.returnFail();
// String token = request.getHeader("token");HttpServletRequest request String token = request.getHeader("token");
String key = RedisKeyUtils.formatKeyWithPrefix(token); String key = RedisKeyUtils.formatKeyWithPrefix(Constants.Redis.PREFIX_TOKEN, token);
if (redisUtils.getValue(key) == null) { if(redisUtils.getValue(key) == null){
log.info("要退出登录的用户未登录"); log.info("要退出登录的用户未登录");
return ResultUtils.returnResult(ResultEnum.FILE_NOT_LOGIN); return ResultUtils.returnResult(ResultEnum.FILE_NOT_LOGIN);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment