mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-04-26 12:09:36 +08:00
add 新增 RemoteConfigService 配置服务 ;
add 新增 RemoteUserService#checkUserNameUnique 校验用户名称是否唯一 ; update 更新 TokenController#register 校验注册配置 ; update 更新 SysLoginService#register 增加验证码校验, 用户名唯一校验 ;
This commit is contained in:
@@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.auth.form.RegisterBody;
|
||||
import org.dromara.auth.properties.CaptchaProperties;
|
||||
import org.dromara.auth.properties.UserPasswordProperties;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.constant.GlobalConstants;
|
||||
@@ -17,6 +18,8 @@ import org.dromara.common.core.constant.TenantConstants;
|
||||
import org.dromara.common.core.enums.LoginType;
|
||||
import org.dromara.common.core.enums.TenantStatus;
|
||||
import org.dromara.common.core.enums.UserType;
|
||||
import org.dromara.common.core.exception.CaptchaException;
|
||||
import org.dromara.common.core.exception.user.CaptchaExpireException;
|
||||
import org.dromara.common.core.exception.user.UserException;
|
||||
import org.dromara.common.core.utils.MessageUtils;
|
||||
import org.dromara.common.core.utils.ServletUtils;
|
||||
@@ -61,6 +64,8 @@ public class SysLoginService {
|
||||
|
||||
@Autowired
|
||||
private UserPasswordProperties userPasswordProperties;
|
||||
@Autowired
|
||||
private final CaptchaProperties captchaProperties;
|
||||
|
||||
/**
|
||||
* 绑定第三方用户
|
||||
@@ -119,12 +124,22 @@ public class SysLoginService {
|
||||
// 校验用户类型是否存在
|
||||
String userType = UserType.getUserType(registerBody.getUserType()).getUserType();
|
||||
|
||||
boolean captchaEnabled = captchaProperties.getEnabled();
|
||||
// 验证码开关
|
||||
if (captchaEnabled) {
|
||||
validateCaptcha(tenantId, username, registerBody.getCode(), registerBody.getUuid());
|
||||
}
|
||||
|
||||
// 注册用户信息
|
||||
RemoteUserBo remoteUserBo = new RemoteUserBo();
|
||||
remoteUserBo.setUserName(username);
|
||||
remoteUserBo.setNickName(username);
|
||||
remoteUserBo.setPassword(BCrypt.hashpw(password));
|
||||
remoteUserBo.setUserType(userType);
|
||||
// 校验用户名是否唯一
|
||||
if (!remoteUserService.checkUserNameUnique(remoteUserBo)) {
|
||||
throw new UserException("user.register.save.error", username);
|
||||
}
|
||||
boolean regFlag = remoteUserService.registerUserInfo(remoteUserBo);
|
||||
if (!regFlag) {
|
||||
throw new UserException("user.register.error");
|
||||
@@ -132,6 +147,27 @@ public class SysLoginService {
|
||||
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param code 验证码
|
||||
* @param uuid 唯一标识
|
||||
*/
|
||||
public void validateCaptcha(String tenantId, String username, String code, String uuid) {
|
||||
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, "");
|
||||
String captcha = RedisUtils.getCacheObject(verifyKey);
|
||||
RedisUtils.deleteObject(verifyKey);
|
||||
if (captcha == null) {
|
||||
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.expire"));
|
||||
throw new CaptchaExpireException();
|
||||
}
|
||||
if (!code.equalsIgnoreCase(captcha)) {
|
||||
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.error"));
|
||||
throw new CaptchaException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录登录信息
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user