1.抽离 getUserByName 方法进行复用
This commit is contained in:
@@ -34,20 +34,7 @@ public class UserController {
|
|||||||
// 用户登陆接口
|
// 用户登陆接口
|
||||||
@PostMapping("doLogin")
|
@PostMapping("doLogin")
|
||||||
public BaseResponse<SystemUsersVO> doLogin(@RequestBody SystemUsersDTO usersDTO) {
|
public BaseResponse<SystemUsersVO> doLogin(@RequestBody SystemUsersDTO usersDTO) {
|
||||||
SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername(),usersDTO.getTenantId());
|
SystemUsers user = getUserByName(usersDTO);
|
||||||
if (user == null) {
|
|
||||||
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
||||||
}
|
|
||||||
if (!usersService.isPasswordMatch(usersDTO.getPassword(), user.getPassword())) {
|
|
||||||
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) {
|
|
||||||
throw new BusinessException(ErrorCode.USER_DISABLE);
|
|
||||||
}
|
|
||||||
if (usersService.isExpired(usersDTO.getTenantId())){
|
|
||||||
throw new BusinessException(ErrorCode.PACKAGE_EXPIRED);
|
|
||||||
}
|
|
||||||
if (!usersService.checkCrawlRole(user.getId())){
|
if (!usersService.checkCrawlRole(user.getId())){
|
||||||
throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED);
|
throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED);
|
||||||
}
|
}
|
||||||
@@ -63,23 +50,11 @@ public class UserController {
|
|||||||
return ResultUtils.success(systemUsersVO);
|
return ResultUtils.success(systemUsersVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 用户登陆接口
|
// 用户登陆接口
|
||||||
@PostMapping("bigbrother-doLogin")
|
@PostMapping("bigbrother-doLogin")
|
||||||
public BaseResponse<SystemUsersVO> bigBrotherDoLogin(@RequestBody SystemUsersDTO usersDTO) {
|
public BaseResponse<SystemUsersVO> bigBrotherDoLogin(@RequestBody SystemUsersDTO usersDTO) {
|
||||||
SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername(),usersDTO.getTenantId());
|
SystemUsers user = getUserByName(usersDTO);
|
||||||
if (user == null) {
|
|
||||||
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
||||||
}
|
|
||||||
if (!usersService.isPasswordMatch(usersDTO.getPassword(), user.getPassword())) {
|
|
||||||
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) {
|
|
||||||
throw new BusinessException(ErrorCode.USER_DISABLE);
|
|
||||||
}
|
|
||||||
if (usersService.isExpired(usersDTO.getTenantId())){
|
|
||||||
throw new BusinessException(ErrorCode.PACKAGE_EXPIRED);
|
|
||||||
}
|
|
||||||
if (!usersService.checkbigBrotherlRole(user.getId())){
|
if (!usersService.checkbigBrotherlRole(user.getId())){
|
||||||
throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED);
|
throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED);
|
||||||
}
|
}
|
||||||
@@ -98,20 +73,7 @@ public class UserController {
|
|||||||
// 用户登陆接口
|
// 用户登陆接口
|
||||||
@PostMapping("aiChat-doLogin")
|
@PostMapping("aiChat-doLogin")
|
||||||
public BaseResponse<SystemUsersVO> aiChatDoLogin(@RequestBody SystemUsersDTO usersDTO) {
|
public BaseResponse<SystemUsersVO> aiChatDoLogin(@RequestBody SystemUsersDTO usersDTO) {
|
||||||
SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername(),usersDTO.getTenantId());
|
SystemUsers user = getUserByName(usersDTO);
|
||||||
if (user == null) {
|
|
||||||
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
||||||
}
|
|
||||||
if (!usersService.isPasswordMatch(usersDTO.getPassword(), user.getPassword())) {
|
|
||||||
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) {
|
|
||||||
throw new BusinessException(ErrorCode.USER_DISABLE);
|
|
||||||
}
|
|
||||||
if (usersService.isExpired(usersDTO.getTenantId())){
|
|
||||||
throw new BusinessException(ErrorCode.PACKAGE_EXPIRED);
|
|
||||||
}
|
|
||||||
if (!usersService.checkAiCHatLoginRole(user.getId())){
|
if (!usersService.checkAiCHatLoginRole(user.getId())){
|
||||||
throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED);
|
throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED);
|
||||||
}
|
}
|
||||||
@@ -126,4 +88,23 @@ public class UserController {
|
|||||||
systemUsersVO.setTokenValue(StpUtil.getTokenValue());
|
systemUsersVO.setTokenValue(StpUtil.getTokenValue());
|
||||||
return ResultUtils.success(systemUsersVO);
|
return ResultUtils.success(systemUsersVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SystemUsers getUserByName(@RequestBody SystemUsersDTO usersDTO) {
|
||||||
|
SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername(),usersDTO.getTenantId());
|
||||||
|
if (user == null) {
|
||||||
|
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
||||||
|
}
|
||||||
|
if (!usersService.isPasswordMatch(usersDTO.getPassword(), user.getPassword())) {
|
||||||
|
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) {
|
||||||
|
throw new BusinessException(ErrorCode.USER_DISABLE);
|
||||||
|
}
|
||||||
|
if (usersService.isExpired(usersDTO.getTenantId())){
|
||||||
|
throw new BusinessException(ErrorCode.PACKAGE_EXPIRED);
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user