Commit 39d5bad9 authored by m1991's avatar m1991

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

parent fcd5b3de
......@@ -109,7 +109,7 @@ public class Constants {
/**
* token相关
*/
public final static String PREFIX_TOKEN = "token:";
public final static String PREFIX_TOKEN = "token";
}
}
......@@ -27,9 +27,9 @@ public class RedisKeyUtils {
*/
public static String formatKeyWithPrefix(String ... args){
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){
key.append(s).append(Constants.Connnector.UNDERLINE);
key.append(s).append(Constants.Connnector.COLON);
}
return key.toString();
}
......
......@@ -331,9 +331,9 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
@Override
public int logout(String token) {
int succ = 0;
String key = RedisKeyUtils.formatKeyWithPrefix(token);
redisUtils.delete(key);
if(redisUtils.getValue(key) == null){
// String key = RedisKeyUtils.formatKeyWithPrefix(token);
redisUtils.delete(token);
if(redisUtils.getValue(token) == null){
succ = 1;
}
return succ;
......
......@@ -193,28 +193,28 @@ public class LoginController {
/**
* 退出登录
*
* @param token
* @param
* @return
*/
@ApiOperation(value = "退出登录", produces = "application/json", notes = "退出登录")
@ApiImplicitParam(paramType = "header", name = "token", value = "用户token", required = true, dataType = "String")
@PostMapping("/logout")
public Result logout(String token) {
log.info("退出登录");
Result result = ResultUtils.returnFail();
// String token = request.getHeader("token");HttpServletRequest request
String key = RedisKeyUtils.formatKeyWithPrefix(token);
if (redisUtils.getValue(key) == null) {
log.info("要退出登录的用户未登录");
return ResultUtils.returnResult(ResultEnum.FILE_NOT_LOGIN);
}
int succ = usersService.logout(token);
if (succ > 0) {
result = ResultUtils.returnSuccess();
public Result logout(HttpServletRequest request) {
log.info("退出登录");
Result result = ResultUtils.returnFail();
String token = request.getHeader("token");
String key = RedisKeyUtils.formatKeyWithPrefix(Constants.Redis.PREFIX_TOKEN, token);
if(redisUtils.getValue(key) == null){
log.info("要退出登录的用户未登录");
return ResultUtils.returnResult(ResultEnum.FILE_NOT_LOGIN);
}
int succ = usersService.logout(token);
if (succ > 0) {
result = ResultUtils.returnSuccess();
}
return result;
}
return result;
}
}
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