|
@@ -3,6 +3,7 @@ package com.backendsys.modules.system.service.impl;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.date.DateUnit;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.backendsys.exception.CustException;
|
|
@@ -12,6 +13,7 @@ import com.backendsys.modules.common.config.security.utils.*;
|
|
|
import com.backendsys.modules.system.dao.SysMobileAreaDao;
|
|
|
import com.backendsys.modules.system.dao.SysUserDao;
|
|
|
import com.backendsys.modules.system.dao.SysUserInfoDao;
|
|
|
+import com.backendsys.modules.system.dao.SysUserRoleDao;
|
|
|
import com.backendsys.modules.system.entity.*;
|
|
|
import com.backendsys.modules.system.service.SysAuthService;
|
|
|
import com.backendsys.modules.system.service.SysCommonService;
|
|
@@ -24,6 +26,7 @@ import jakarta.servlet.ServletOutputStream;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -38,6 +41,8 @@ import java.util.concurrent.TimeUnit;
|
|
|
@Service
|
|
|
public class SysAuthServiceImpl implements SysAuthService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private Environment env;
|
|
|
@Autowired
|
|
|
private JwtUtil jwtUtil;
|
|
|
@Autowired
|
|
@@ -56,6 +61,8 @@ public class SysAuthServiceImpl implements SysAuthService {
|
|
|
@Autowired
|
|
|
private SysUserDao sysUserDao;
|
|
|
@Autowired
|
|
|
+ private SysUserRoleDao sysUserRoleDao;
|
|
|
+ @Autowired
|
|
|
private SysUserInfoDao sysUserInfoDao;
|
|
|
@Autowired
|
|
|
private SysUserService sysUserService;
|
|
@@ -151,7 +158,7 @@ public class SysAuthServiceImpl implements SysAuthService {
|
|
|
|
|
|
// 判断用户是否审核
|
|
|
Integer audit_status = sysUserInfo.getAudit_status();
|
|
|
- if (audit_status != null && audit_status.equals(1)) throw new CustException("用户审核中");
|
|
|
+ if (audit_status != null && audit_status.equals(1)) throw new CustException("用户正在审核中");
|
|
|
if (audit_status != null && audit_status.equals(-1)) throw new CustException("用户审核未通过,请与客服联系");
|
|
|
|
|
|
// 判断用户是否启用
|
|
@@ -314,13 +321,16 @@ public class SysAuthServiceImpl implements SysAuthService {
|
|
|
Integer phoneAreaCode = sysUserDTO.getPhone_area_code();
|
|
|
Integer phoneValidCode = sysUserDTO.getPhone_valid_code();
|
|
|
|
|
|
- // 判断是否处于登录错误的冻结状态 (2分钟内错误5次,则出现冻结提示)
|
|
|
- lockStatusUtil.checkLockStatus(APPLICATION_NAME + "-register-error", username);
|
|
|
- lockStatusUtil.checkLockStatus(APPLICATION_NAME + "-register-error", phone);
|
|
|
- // 判断图形验证码是否正确
|
|
|
- if (!captchaUtil.isCaptchaValid(captcha, httpRequestUtil.getKaptchaKey())) {
|
|
|
- loginFail("验证码错误", username, false);
|
|
|
- return null;
|
|
|
+ String activeProfile = env.getActiveProfiles()[0];
|
|
|
+ if (!"local".equals(activeProfile)) {
|
|
|
+ // 判断是否处于登录错误的冻结状态 (2分钟内错误5次,则出现冻结提示)
|
|
|
+ lockStatusUtil.checkLockStatus(APPLICATION_NAME + "-register-error", username);
|
|
|
+ lockStatusUtil.checkLockStatus(APPLICATION_NAME + "-register-error", phone);
|
|
|
+ // 判断图形验证码是否正确
|
|
|
+ if (!captchaUtil.isCaptchaValid(captcha, httpRequestUtil.getKaptchaKey())) {
|
|
|
+ loginFail("验证码错误", username, false);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// [查询] 判断用户名是否存在
|
|
@@ -328,12 +338,14 @@ public class SysAuthServiceImpl implements SysAuthService {
|
|
|
if (sysUser1 != null) throw new CustException("用户名 (" + username + ") 已被注册");
|
|
|
|
|
|
// 判断短信验证码是否正确
|
|
|
- String redisKey = APPLICATION_NAME + "-sms-register" + "-" + phone;
|
|
|
- Integer smsCode = redisUtil.getCacheObject(redisKey);
|
|
|
- // 判断是否发送验证码
|
|
|
- if ("false".equals(SMS_DEBUG) && smsCode == null) throw new CustException("请先发送短信验证码");
|
|
|
- // 判断短信验证码是否错误
|
|
|
- if ("false".equals(SMS_DEBUG) && !smsCode.equals(phoneValidCode)) loginFail("短信验证码错误", phone, true);
|
|
|
+ if (!"local".equals(activeProfile)) {
|
|
|
+ String redisKey = APPLICATION_NAME + "-sms-register" + "-" + phone;
|
|
|
+ Integer smsCode = redisUtil.getCacheObject(redisKey);
|
|
|
+ // 判断是否发送验证码
|
|
|
+ if ("false".equals(SMS_DEBUG) && smsCode == null) throw new CustException("请先发送短信验证码");
|
|
|
+ // 判断短信验证码是否错误
|
|
|
+ if ("false".equals(SMS_DEBUG) && !smsCode.equals(phoneValidCode)) loginFail("短信验证码错误", phone, true);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// [查询] 判断手机号是否存在
|
|
@@ -359,14 +371,29 @@ public class SysAuthServiceImpl implements SysAuthService {
|
|
|
|
|
|
// 做成后台可控制?
|
|
|
|
|
|
- // 注册时,默认使用 权限
|
|
|
- registerEntity.setRole_id(Arrays.asList(3L));
|
|
|
|
|
|
+ // 邀请码
|
|
|
+ registerEntity.setInvite_code(sysUserDTO.getInvite_code());
|
|
|
|
|
|
+ // 注册时,默认使用 权限 (DEFAULT)
|
|
|
+ String role_sign = "DEFAULT";
|
|
|
|
|
|
- registerEntity.setInvite_code(sysUserDTO.getInvite_code());
|
|
|
- // 注册时,状态为禁用
|
|
|
- registerEntity.setStatus(-1);
|
|
|
+ // 如果邀请码是 (Material),则注册成为 [素材游客]
|
|
|
+ if ("Material".equals(sysUserDTO.getInvite_code())) role_sign = "MATERIAL_GUEST";
|
|
|
+
|
|
|
+ LambdaQueryWrapper<SysUserRole> wrapperRole = new LambdaQueryWrapper<>();
|
|
|
+ wrapperRole.eq(SysUserRole::getRole_sign, role_sign);
|
|
|
+ SysUserRole roleDetail = sysUserRoleDao.selectOne(wrapperRole);
|
|
|
+ registerEntity.setRole_id(Arrays.asList(roleDetail.getRole_id()));
|
|
|
+
|
|
|
+ // 注册时,审核状态为 待审核 (-1拒绝, 1待审核, 2审核通过)
|
|
|
+ registerEntity.setAudit_status(1);
|
|
|
+
|
|
|
+ // 注册时,状态为 禁用
|
|
|
+ // registerEntity.setStatus(-1);
|
|
|
+
|
|
|
+ // 随机昵称 (6位)
|
|
|
+ registerEntity.setNickname("用户" + RandomUtil.randomStringUpper(6));
|
|
|
|
|
|
// 创建用户
|
|
|
sysUserDao.insertUser(registerEntity);
|