♻️ Refactoring code.refactor logout

This commit is contained in:
lishangbu 2019-03-22 19:06:08 +08:00
parent fed4d460a3
commit 217d9898da
1 changed files with 21 additions and 10 deletions

View File

@ -19,6 +19,7 @@ package com.pig4cloud.pig.auth.endpoint;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.constant.CommonConstants;
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.security.service.PigUser;
@ -64,18 +65,28 @@ public class PigTokenEndpoint {
*
* @param authHeader Authorization
*/
@GetMapping("/logout")
@DeleteMapping("/logout")
public R<Boolean> logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader) {
if (StringUtils.hasText(authHeader)) {
if (StrUtil.isBlank(authHeader)) {
return R.<Boolean>builder()
.code(CommonConstants.FAIL)
.data(Boolean.FALSE)
.msg("退出失败token 为空").build();
}
String tokenValue = authHeader.replace(OAuth2AccessToken.BEARER_TYPE, StrUtil.EMPTY).trim();
OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
if (accessToken == null || StrUtil.isBlank(accessToken.getValue())) {
return new R<>(false, "退出失败token 为空");
return R.<Boolean>builder()
.code(CommonConstants.FAIL)
.data(Boolean.FALSE)
.msg("退出失败token 无效").build();
}
tokenStore.removeAccessToken(accessToken);
}
return new R<>(Boolean.TRUE);
return R.<Boolean>builder()
.code(CommonConstants.SUCCESS)
.data(Boolean.TRUE)
.build();
}
/**
@ -106,7 +117,7 @@ public class PigTokenEndpoint {
}
List<Map<String, String>> list = new ArrayList<>();
if (StringUtils.isEmpty(MapUtil.getInt(params, CURRENT)) || StringUtils.isEmpty(MapUtil.getInt(params, CURRENT))) {
if (StringUtils.isEmpty(MapUtil.getInt(params, CURRENT)) || StringUtils.isEmpty(MapUtil.getInt(params, SIZE))) {
params.put(CURRENT, 1);
params.put(SIZE, 20);
}