Commit 52816adc authored by tangtuo's avatar tangtuo

修改登录失败的异常处理

parent 45103940
...@@ -56,5 +56,10 @@ ...@@ -56,5 +56,10 @@
<option name="name" value="local private nexus" /> <option name="name" value="local private nexus" />
<option name="url" value="http://maven.citydo.com.cn/repository/maven-public/" /> <option name="url" value="http://maven.citydo.com.cn/repository/maven-public/" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://maven.aliyun.com/repository/public" />
</remote-repository>
</component> </component>
</project> </project>
\ No newline at end of file
package com.fzm.common.exception.handler; package com.fzm.common.exception.handler;
import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.exception.*;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpStatus; import cn.hutool.http.HttpStatus;
...@@ -46,24 +46,31 @@ public class GlobalExceptionHandler { ...@@ -46,24 +46,31 @@ public class GlobalExceptionHandler {
return ResponseModel.fail(exception); return ResponseModel.fail(exception);
} }
@ExceptionHandler(value = NotLoginException.class) @ExceptionHandler(value = SaTokenException.class)
public ResponseModel<String> handlerNotLoginException(NotLoginException exception) { public ResponseModel<String> handlerNotLoginException(SaTokenException exception) {
log.error(exception.getMessage(), exception); log.error(exception.getMessage(), exception);
response.setStatus(HttpStatus.HTTP_INTERNAL_ERROR); response.setStatus(HttpStatus.HTTP_INTERNAL_ERROR);
if (exception.getMessage().contains("token已被顶下线")) { if (exception instanceof NotLoginException) {
// 获取已过期的token if (exception.getMessage().contains("token已被顶下线")) {
String expireToken = StpUtil.getTokenValue(); // 获取已过期的token
// 从已过期的token中获取用户id String expireToken = StpUtil.getTokenValue();
Integer userId = JwtUtil.getUserIdFromToken(expireToken); // 从已过期的token中获取用户id
// 获取最新的token Integer userId = JwtUtil.getUserIdFromToken(expireToken);
String tokenValue = StpUtil.getTokenValueByLoginId(userId); // 获取最新的token
Date createTime = JwtUtil.getCreateTimeFromToken(tokenValue); String tokenValue = StpUtil.getTokenValueByLoginId(userId);
String format = DateUtil.format(createTime, "yyyy-MM-dd HH:mm:ss"); Date createTime = JwtUtil.getCreateTimeFromToken(tokenValue);
return ResponseModel.fail(ResultCode.UNAUTHORIZED, String format = DateUtil.format(createTime, "yyyy-MM-dd HH:mm:ss");
String.format("您的账号于 %s 登录另外一台设备,如非您本人所为,请立即修改密码", format)); return ResponseModel.fail(ResultCode.UNAUTHORIZED,
String.format("您的账号于 %s 登录另外一台设备,如非您本人所为,请立即修改密码", format));
} else {
return ResponseModel.fail(ResultCode.UNAUTHORIZED, exception.getMessage());
}
} else if (exception instanceof NotPermissionException || exception instanceof NotRoleException || exception instanceof StopMatchException) {
return ResponseModel.fail(ResultCode.FORBIDDEN, ResultCode.FORBIDDEN.getMessage());
} else {
return ResponseModel.fail(exception);
} }
return ResponseModel.fail(exception);
} }
@ExceptionHandler(value = {MethodArgumentNotValidException.class}) @ExceptionHandler(value = {MethodArgumentNotValidException.class})
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
<select id="list" resultType="com.fzm.common.entity.vo.UserListVo"> <select id="list" resultType="com.fzm.common.entity.vo.UserListVo">
SELECT u.id, SELECT u.id,
u.telephone, u.telephone,
u.nickname, u.nickname,
u.auth_type, u.auth_type,
u.create_date AS registerDate, u.create_date AS registerDate,
(select count(0) from tb_nft n where u.id = n.user_id) as publishCount (select count(0) from tb_nft n where u.id = n.user_id and n.nft_hash != '') as publishCount
FROM tb_user u FROM tb_user u
where 1=1 where 1=1
<if test="telephone != null and telephone != ''"> <if test="telephone != null and telephone != ''">
......
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