|
@@ -1,7 +1,6 @@
|
|
|
package com.vber.web.service;
|
|
package com.vber.web.service;
|
|
|
|
|
|
|
|
import cn.dev33.satoken.secure.BCrypt;
|
|
import cn.dev33.satoken.secure.BCrypt;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.vber.common.core.constant.Constants;
|
|
import com.vber.common.core.constant.Constants;
|
|
|
import com.vber.common.core.constant.GlobalConstants;
|
|
import com.vber.common.core.constant.GlobalConstants;
|
|
@@ -11,10 +10,7 @@ import com.vber.common.core.exception.user.CaptchaException;
|
|
|
import com.vber.common.core.exception.user.CaptchaExpireException;
|
|
import com.vber.common.core.exception.user.CaptchaExpireException;
|
|
|
import com.vber.common.core.exception.user.UserException;
|
|
import com.vber.common.core.exception.user.UserException;
|
|
|
import com.vber.common.core.utils.MessageUtils;
|
|
import com.vber.common.core.utils.MessageUtils;
|
|
|
-import com.vber.common.core.utils.ServletUtils;
|
|
|
|
|
-import com.vber.common.core.utils.SpringUtils;
|
|
|
|
|
import com.vber.common.core.utils.StringUtils;
|
|
import com.vber.common.core.utils.StringUtils;
|
|
|
-import com.vber.common.log.event.LogininforEvent;
|
|
|
|
|
import com.vber.common.redis.utils.RedisUtils;
|
|
import com.vber.common.redis.utils.RedisUtils;
|
|
|
import com.vber.common.tenant.helper.TenantHelper;
|
|
import com.vber.common.tenant.helper.TenantHelper;
|
|
|
import com.vber.common.web.config.properties.CaptchaProperties;
|
|
import com.vber.common.web.config.properties.CaptchaProperties;
|
|
@@ -25,6 +21,7 @@ import com.vber.system.service.ISysUserService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 注册校验方法
|
|
* 注册校验方法
|
|
|
*
|
|
*
|
|
@@ -59,11 +56,7 @@ public class SysRegisterService {
|
|
|
sysUser.setPassword(BCrypt.hashpw(password));
|
|
sysUser.setPassword(BCrypt.hashpw(password));
|
|
|
sysUser.setUserType(userType);
|
|
sysUser.setUserType(userType);
|
|
|
|
|
|
|
|
- boolean exist = TenantHelper.dynamic(tenantId, () -> {
|
|
|
|
|
- return userMapper.exists(new LambdaQueryWrapper<SysUser>()
|
|
|
|
|
- .eq(SysUser::getUserName, sysUser.getUserName())
|
|
|
|
|
- .ne(ObjectUtil.isNotNull(sysUser.getUserId()), SysUser::getUserId, sysUser.getUserId()));
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ boolean exist = TenantHelper.dynamic(tenantId, () -> userMapper.exists(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, sysUser.getUserName())));
|
|
|
if (exist) {
|
|
if (exist) {
|
|
|
throw new UserException("user.register.save.error", username);
|
|
throw new UserException("user.register.save.error", username);
|
|
|
}
|
|
}
|
|
@@ -71,7 +64,7 @@ public class SysRegisterService {
|
|
|
if (!regFlag) {
|
|
if (!regFlag) {
|
|
|
throw new UserException("user.register.error");
|
|
throw new UserException("user.register.error");
|
|
|
}
|
|
}
|
|
|
- recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success"));
|
|
|
|
|
|
|
+ recordLogininfor(tenantId, username, MessageUtils.message("user.register.success"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -86,11 +79,11 @@ public class SysRegisterService {
|
|
|
String captcha = RedisUtils.getCacheObject(verifyKey);
|
|
String captcha = RedisUtils.getCacheObject(verifyKey);
|
|
|
RedisUtils.deleteObject(verifyKey);
|
|
RedisUtils.deleteObject(verifyKey);
|
|
|
if (captcha == null) {
|
|
if (captcha == null) {
|
|
|
- recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.expire"));
|
|
|
|
|
|
|
+ recordLogininfor(tenantId, username, MessageUtils.message("user.jcaptcha.expire"));
|
|
|
throw new CaptchaExpireException();
|
|
throw new CaptchaExpireException();
|
|
|
}
|
|
}
|
|
|
if (!code.equalsIgnoreCase(captcha)) {
|
|
if (!code.equalsIgnoreCase(captcha)) {
|
|
|
- recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.error"));
|
|
|
|
|
|
|
+ recordLogininfor(tenantId, username, MessageUtils.message("user.jcaptcha.error"));
|
|
|
throw new CaptchaException();
|
|
throw new CaptchaException();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -100,18 +93,11 @@ public class SysRegisterService {
|
|
|
*
|
|
*
|
|
|
* @param tenantId 租户ID
|
|
* @param tenantId 租户ID
|
|
|
* @param username 用户名
|
|
* @param username 用户名
|
|
|
- * @param status 状态
|
|
|
|
|
* @param message 消息内容
|
|
* @param message 消息内容
|
|
|
- * @return
|
|
|
|
|
*/
|
|
*/
|
|
|
- private void recordLogininfor(String tenantId, String username, String status, String message) {
|
|
|
|
|
- LogininforEvent logininforEvent = new LogininforEvent();
|
|
|
|
|
- logininforEvent.setTenantId(tenantId);
|
|
|
|
|
- logininforEvent.setUsername(username);
|
|
|
|
|
- logininforEvent.setStatus(status);
|
|
|
|
|
- logininforEvent.setMessage(message);
|
|
|
|
|
- logininforEvent.setRequest(ServletUtils.getRequest());
|
|
|
|
|
- SpringUtils.context().publishEvent(logininforEvent);
|
|
|
|
|
|
|
+ private void recordLogininfor(String tenantId, String username, String message) {
|
|
|
|
|
+ SysLoginService.buildLoginEvent(tenantId, username, Constants.REGISTER, message);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|