Commit f0082832 authored by tangtuo's avatar tangtuo

新增登出接口

nft详情接口加入是否收藏字段
parent 73a24985
...@@ -12,7 +12,8 @@ public class InterceptorConfig implements WebMvcConfigurer { ...@@ -12,7 +12,8 @@ public class InterceptorConfig implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authenticationInterceptor()) registry.addInterceptor(authenticationInterceptor())
.addPathPatterns("/**"); // 拦截所有请求,通过判断是否有 @LoginRequired 注解 决定是否需要登录 .excludePathPatterns("/user/login", "/admin/login", "/verificationCode/send/sms")
.addPathPatterns("/**");
} }
@Bean @Bean
public AuthenticationInterceptor authenticationInterceptor() { public AuthenticationInterceptor authenticationInterceptor() {
......
...@@ -56,6 +56,9 @@ public class NftVo { ...@@ -56,6 +56,9 @@ public class NftVo {
@ApiModelProperty("授权阅读 0-不需要授权 1-需要授权") @ApiModelProperty("授权阅读 0-不需要授权 1-需要授权")
private Integer isGrant; private Integer isGrant;
@ApiModelProperty("是否收藏")
private Boolean collection;
@ApiModelProperty("关于nft") @ApiModelProperty("关于nft")
private String aboutNft; private String aboutNft;
...@@ -73,5 +76,6 @@ public class NftVo { ...@@ -73,5 +76,6 @@ public class NftVo {
this.publishTime = DateUtil.format(nft.getPublishTime(), "yyyy/MM/dd HH:mm:ss"); this.publishTime = DateUtil.format(nft.getPublishTime(), "yyyy/MM/dd HH:mm:ss");
this.isArchives = nft.getIsArchives(); this.isArchives = nft.getIsArchives();
this.isGrant = nft.getIsGrant(); this.isGrant = nft.getIsGrant();
this.collection = false;
} }
} }
...@@ -140,7 +140,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us ...@@ -140,7 +140,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
case "voice": case "voice":
return smsProperties.getVoiceLoginCodetype(); return smsProperties.getVoiceLoginCodetype();
default: default:
throw GlobalException.newException(ResultCode.CODE_ERROR); throw GlobalException.newException(ResultCode.VALIDATE_FAILED, "短信类型【" + type + "】的传参有误,取值范围是{sms,email,voice}");
} }
} }
......
...@@ -55,6 +55,7 @@ public class JwtUtil { ...@@ -55,6 +55,7 @@ public class JwtUtil {
.getBody(); .getBody();
} catch (Exception e) { } catch (Exception e) {
log.info("JWT格式验证失败:{}", token); log.info("JWT格式验证失败:{}", token);
throw GlobalException.newException(ResultCode.UNAUTHORIZED, e.getMessage());
} }
return claims; return claims;
} }
...@@ -80,7 +81,7 @@ public class JwtUtil { ...@@ -80,7 +81,7 @@ public class JwtUtil {
Claims claims = getClaimsFromToken(token); Claims claims = getClaimsFromToken(token);
return claims.get(CLAIM_KEY_CREATED, Date.class); return claims.get(CLAIM_KEY_CREATED, Date.class);
} catch (Exception e) { } catch (Exception e) {
throw GlobalException.newException(ResultCode.TOKEN_VALID_ERROR, e.getMessage()); throw GlobalException.newException(ResultCode.UNAUTHORIZED, e.getMessage());
} }
} }
...@@ -92,7 +93,7 @@ public class JwtUtil { ...@@ -92,7 +93,7 @@ public class JwtUtil {
Claims claims = getClaimsFromToken(token); Claims claims = getClaimsFromToken(token);
return claims.get(CLAIM_KEY_USERID, Integer.class); return claims.get(CLAIM_KEY_USERID, Integer.class);
} catch (Exception e) { } catch (Exception e) {
throw GlobalException.newException(ResultCode.TOKEN_VALID_ERROR, e.getMessage()); throw GlobalException.newException(ResultCode.UNAUTHORIZED, e.getMessage());
} }
} }
...@@ -104,7 +105,7 @@ public class JwtUtil { ...@@ -104,7 +105,7 @@ public class JwtUtil {
Claims claims = getClaimsFromToken(token); Claims claims = getClaimsFromToken(token);
return claims.get(CLAIM_KEY_APP_ID, String.class); return claims.get(CLAIM_KEY_APP_ID, String.class);
} catch (Exception e) { } catch (Exception e) {
throw GlobalException.newException(ResultCode.TOKEN_VALID_ERROR, e.getMessage()); throw GlobalException.newException(ResultCode.UNAUTHORIZED, e.getMessage());
} }
} }
......
...@@ -2,6 +2,7 @@ package com.fzm.portal.controller; ...@@ -2,6 +2,7 @@ package com.fzm.portal.controller;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import com.fzm.common.annotation.Authentication; import com.fzm.common.annotation.Authentication;
import com.fzm.common.constant.RedisConstant;
import com.fzm.common.constant.SystemConstant; import com.fzm.common.constant.SystemConstant;
import com.fzm.common.entity.Nft; import com.fzm.common.entity.Nft;
import com.fzm.common.entity.NftDto; import com.fzm.common.entity.NftDto;
...@@ -18,6 +19,7 @@ import com.fzm.common.service.UserService; ...@@ -18,6 +19,7 @@ import com.fzm.common.service.UserService;
import com.fzm.common.utils.JwtUtil; import com.fzm.common.utils.JwtUtil;
import com.fzm.common.utils.OssUtil; import com.fzm.common.utils.OssUtil;
import com.fzm.common.utils.QRCodeUtil; import com.fzm.common.utils.QRCodeUtil;
import com.fzm.common.utils.RedisUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
...@@ -58,6 +60,9 @@ public class NftController { ...@@ -58,6 +60,9 @@ public class NftController {
private CategoryService categoryService; private CategoryService categoryService;
@Resource @Resource
private RedisUtil redisUtil;
@Resource
private HttpServletRequest request; private HttpServletRequest request;
/** /**
...@@ -101,7 +106,7 @@ public class NftController { ...@@ -101,7 +106,7 @@ public class NftController {
@GetMapping("get/{id}") @GetMapping("get/{id}")
@ApiOperation(value = "获取nft详情") @ApiOperation(value = "获取nft详情")
public ResponseModel<NftVo> getById(@PathVariable Integer id) { public ResponseModel<NftVo> getById(@PathVariable Integer id, @RequestHeader(required = false) String Authorization) {
Nft nft = nftService.getById(id); Nft nft = nftService.getById(id);
if (nft == null) { if (nft == null) {
throw GlobalException.newException(ResultCode.DATA_ERROR, "没找到此nft的详情"); throw GlobalException.newException(ResultCode.DATA_ERROR, "没找到此nft的详情");
...@@ -112,6 +117,11 @@ public class NftController { ...@@ -112,6 +117,11 @@ public class NftController {
} }
NftVo nftVo = new NftVo(nft, user); NftVo nftVo = new NftVo(nft, user);
nftVo.setCategory(categoryService.getById(nft.getCategoryId()).getCategoryName()); nftVo.setCategory(categoryService.getById(nft.getCategoryId()).getCategoryName());
if (StringUtils.isNotBlank(Authorization)) {
Integer userId = JwtUtil.getUserIdFromToken(Authorization);
Boolean collection = redisUtil.sIsMember(RedisConstant.COLLECTION_USER_PREFIX + userId, id.toString());
nftVo.setCollection(collection);
}
return ResponseModel.success(nftVo); return ResponseModel.success(nftVo);
} }
......
...@@ -81,6 +81,15 @@ public class UserController { ...@@ -81,6 +81,15 @@ public class UserController {
return ResponseModel.success(user != null && StringUtils.isNotBlank(user.getPassword())); return ResponseModel.success(user != null && StringUtils.isNotBlank(user.getPassword()));
} }
@Authentication
@PostMapping(value = "/logout")
@ApiOperation(value = "判断用户是否已注册过")
public ResponseModel<Boolean> logout(@RequestHeader String Authorization) {
Integer userId = JwtUtil.getUserIdFromToken(Authorization);
redisUtil.delete(RedisConstant.PORTAL_USER_TOKEN_PREFIX + userId);
return ResponseModel.success();
}
//@ApiOperation(value = "设置密码") //@ApiOperation(value = "设置密码")
public ResponseModel<Boolean> setPassword() { public ResponseModel<Boolean> setPassword() {
return ResponseModel.success(); return ResponseModel.success();
......
package com.fzm.portal; package com.fzm.portal;
import cn.fzm.chain.simplesdk.client.ParaChainClient; import cn.fzm.chain.simplesdk.client.ParaChainClient;
import com.fzm.common.constant.RedisConstant;
import com.fzm.common.utils.JsonUtil; import com.fzm.common.utils.JsonUtil;
import com.fzm.common.utils.RedisUtil; import com.fzm.common.utils.RedisUtil;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -29,8 +30,7 @@ class LyPortalApplicationTests { ...@@ -29,8 +30,7 @@ class LyPortalApplicationTests {
@Test @Test
void contextLoads() { void contextLoads() {
System.out.println(redisUtil.setMembers("user:collect:2")); System.out.println(redisUtil.sIsMember(RedisConstant.COLLECTION_USER_PREFIX + 9, "2"));
System.out.println(redisUtil.sSize("user:collect:2"));
} }
} }
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