修改异常返回信息结果

master
bynt 2 years ago
parent 0d3c221d0b
commit 038b3661fb

@ -85,7 +85,7 @@ public enum ResultCode implements IResultCode {
/**
*
*/
USER_ACCOUNT_EXPIRED(11008, "用户账号过期"),
USER_ACCOUNT_EXPIRED(11008, "用户账号过期"),
/**
*
*/

@ -1,5 +1,6 @@
package com.baiye.component;
import com.baiye.core.base.api.ResultCode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
@ -34,7 +35,7 @@ public class ResourceAuthExceptionEntryPoint implements AuthenticationEntryPoint
result.put("code", HttpStatus.UNAUTHORIZED.value());
if (e!=null){
result.put("msg","error");
result.put("data",e.getMessage());
result.put("data", ResultCode.USER_ACCOUNT_EXPIRED.getMsg());
}
response.setStatus(HttpStatus.UNAUTHORIZED.value());
PrintWriter writer = response.getWriter();

@ -49,7 +49,8 @@ public class CustomWebRespExceptionTranslator implements WebResponseExceptionTra
return buildResponseEntity(ApiError.error(message));
}
if (StringUtils.containsIgnoreCase(e.getMessage(), "locked")) {
if (StringUtils.containsIgnoreCase(e.getMessage(), "locked")
|| StringUtils.containsIgnoreCase(e.getMessage(), "User is disabled")) {
message = "用户已被锁定,请联系管理员";
return buildResponseEntity(ApiError.error(message));
}

@ -35,7 +35,10 @@ import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.security.authentication.BadCredentialsException;
@ -54,9 +57,8 @@ import java.util.*;
import java.util.stream.Collectors;
/**
*
* @description
* @author Enzo
* @description
* @create: 2020-08-11 16:17
*/
@Service
@ -67,6 +69,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
private final UserMapper userMapper;
private final CacheManager cacheManager;
private final FileProperties properties;
private final UserMapStruct userMapStruct;
@ -358,11 +361,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
/**
*
*
* @param userDto
* @param encode
*/
@Override
@Transactional(rollbackFor = Exception.class)
@CacheEvict(key = "'username:' + #userDto.username")
public void updatePassword(UserDto userDto, String encode) {
boolean update = this.update(Wrappers.<User>lambdaUpdate().set(User::getPassword, encode)
.set(User::getPwdResetTime, LocalDateTime.now(ZoneId.systemDefault()))
@ -374,7 +379,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
try {
this.remoteAuthService.delete(Collections.singleton(userDto.getId()));
} catch (Exception e) {
throw new RuntimeException(e);
throw new BadRequestException(ResultCode.ERROR.getMsg());
}
Cache cache = this.cacheManager.getCache(CacheKey.USER_DETAILS);
if (cache != null) {
cache.evict(userDto.getUsername());
}
}

Loading…
Cancel
Save