mirror of https://gitee.com/stylefeng/roses
【8.0】【auth】更新用户状态的修改
parent
59e44f2ab8
commit
66446915c7
|
@ -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", "账号或密码错误!");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误编码
|
* 错误编码
|
||||||
|
|
|
@ -239,6 +239,8 @@ public class LoginService {
|
||||||
private Integer validatePasswordRetryTimes(LoginRequest loginRequest) {
|
private Integer validatePasswordRetryTimes(LoginRequest loginRequest) {
|
||||||
Integer loginErrorCount = loginErrorCountCacheApi.get(loginRequest.getAccount());
|
Integer loginErrorCount = loginErrorCountCacheApi.get(loginRequest.getAccount());
|
||||||
if (loginErrorCount != null && loginErrorCount >= LoginConfigExpander.getMaxErrorLoginCount()) {
|
if (loginErrorCount != null && loginErrorCount >= LoginConfigExpander.getMaxErrorLoginCount()) {
|
||||||
|
// 修改用户状态为锁定
|
||||||
|
sysUserServiceApi.lockUserStatus(loginRequest.getTenantCode(), loginRequest.getAccount());
|
||||||
throw new AuthException(AuthExceptionEnum.LOGIN_LOCKED);
|
throw new AuthException(AuthExceptionEnum.LOGIN_LOCKED);
|
||||||
}
|
}
|
||||||
return loginErrorCount;
|
return loginErrorCount;
|
||||||
|
|
|
@ -136,4 +136,12 @@ public interface SysUserServiceApi {
|
||||||
*/
|
*/
|
||||||
UserInfoDetailDTO getUserDetail(Long userId);
|
UserInfoDetailDTO getUserDetail(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 锁定用户状态
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2023/10/3 22:11
|
||||||
|
*/
|
||||||
|
void lockUserStatus(String tenantCode, String account);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,15 +46,10 @@ public enum UserStatusEnum implements ReadableEnum<UserStatusEnum> {
|
||||||
*/
|
*/
|
||||||
ENABLE(1, "启用"),
|
ENABLE(1, "启用"),
|
||||||
|
|
||||||
/**
|
|
||||||
* 禁用
|
|
||||||
*/
|
|
||||||
DISABLE(2, "禁用"),
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 冻结
|
* 冻结
|
||||||
*/
|
*/
|
||||||
FREEZE(3, "冻结");
|
DISABLE(2, "冻结");
|
||||||
|
|
||||||
private final Integer code;
|
private final Integer code;
|
||||||
|
|
||||||
|
@ -105,7 +100,7 @@ public enum UserStatusEnum implements ReadableEnum<UserStatusEnum> {
|
||||||
if (code == null) {
|
if (code == null) {
|
||||||
throw new ServiceException(UserExceptionEnum.REQUEST_USER_STATUS_EMPTY);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
throw new SysException(UserExceptionEnum.REQUEST_USER_STATUS_ERROR, code);
|
throw new SysException(UserExceptionEnum.REQUEST_USER_STATUS_ERROR, code);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
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.context.LoginContext;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi;
|
import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||||
|
@ -65,6 +66,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
@Resource
|
@Resource
|
||||||
private FileInfoApi fileInfoApi;
|
private FileInfoApi fileInfoApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TenantCodeGetApi tenantCodeGetApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void add(SysUserRequest sysUserRequest) {
|
public void add(SysUserRequest sysUserRequest) {
|
||||||
|
@ -543,6 +547,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
return result;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取信息
|
* 获取信息
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue