|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 记录登录信息
|
|
|
|
|
*
|
|
|
|
|