【8.0】【auth】更新用户状态的修改

pull/57/head
fengshuonan 2023-10-03 23:20:09 +08:00
parent 59e44f2ab8
commit 66446915c7
5 changed files with 34 additions and 8 deletions

View File

@ -121,7 +121,7 @@ public enum AuthExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
LOGIN_LOCKED(RuleConstants.BUSINESS_ERROR_TYPE_CODE + AuthConstants.AUTH_EXCEPTION_STEP_CODE + "18", "密码重试次数过多,帐号被锁定");
LOGIN_LOCKED(RuleConstants.BUSINESS_ERROR_TYPE_CODE + AuthConstants.AUTH_EXCEPTION_STEP_CODE + "18", "账号或密码错误!");
/**
*

View File

@ -239,6 +239,8 @@ public class LoginService {
private Integer validatePasswordRetryTimes(LoginRequest loginRequest) {
Integer loginErrorCount = loginErrorCountCacheApi.get(loginRequest.getAccount());
if (loginErrorCount != null && loginErrorCount >= LoginConfigExpander.getMaxErrorLoginCount()) {
// 修改用户状态为锁定
sysUserServiceApi.lockUserStatus(loginRequest.getTenantCode(), loginRequest.getAccount());
throw new AuthException(AuthExceptionEnum.LOGIN_LOCKED);
}
return loginErrorCount;

View File

@ -136,4 +136,12 @@ public interface SysUserServiceApi {
*/
UserInfoDetailDTO getUserDetail(Long userId);
/**
*
*
* @author fengshuonan
* @since 2023/10/3 22:11
*/
void lockUserStatus(String tenantCode, String account);
}

View File

@ -46,15 +46,10 @@ public enum UserStatusEnum implements ReadableEnum<UserStatusEnum> {
*/
ENABLE(1, "启用"),
/**
*
*/
DISABLE(2, "禁用"),
/**
*
*/
FREEZE(3, "冻结");
DISABLE(2, "冻结");
private final Integer code;
@ -105,7 +100,7 @@ public enum UserStatusEnum implements ReadableEnum<UserStatusEnum> {
if (code == null) {
throw new ServiceException(UserExceptionEnum.REQUEST_USER_STATUS_EMPTY);
}
if (ENABLE.getCode().equals(code) || DISABLE.getCode().equals(code) || FREEZE.getCode().equals(code)) {
if (ENABLE.getCode().equals(code) || DISABLE.getCode().equals(code)) {
return;
}
throw new SysException(UserExceptionEnum.REQUEST_USER_STATUS_ERROR, code);

View File

@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.stylefeng.roses.kernel.auth.api.TenantCodeGetApi;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
@ -65,6 +66,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Resource
private FileInfoApi fileInfoApi;
@Resource
private TenantCodeGetApi tenantCodeGetApi;
@Override
@Transactional(rollbackFor = Exception.class)
public void add(SysUserRequest sysUserRequest) {
@ -543,6 +547,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return result;
}
@Override
public void lockUserStatus(String tenantCode, String account) {
// 获取租户id
Long tenantId = tenantCodeGetApi.getTenantIdByCode(tenantCode);
try {
TenantIdHolder.set(tenantId);
LambdaUpdateWrapper<SysUser> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.eq(SysUser::getAccount, account);
lambdaUpdateWrapper.set(SysUser::getStatusFlag, UserStatusEnum.DISABLE.getKey());
this.update(lambdaUpdateWrapper);
} finally {
TenantIdHolder.remove();
}
}
/**
*
*