| | |
| | | import cn.dev33.satoken.secure.BCrypt; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.constant.GlobalConstants; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.model.RegisterBody; |
| | | import com.ruoyi.common.core.enums.UserType; |
| | | import com.ruoyi.common.core.exception.user.CaptchaException; |
| | |
| | | import com.ruoyi.common.web.config.properties.CaptchaProperties; |
| | | import com.ruoyi.system.domain.bo.SysUserBo; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import jakarta.servlet.http.HttpServletRequest; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | * 注册 |
| | | */ |
| | | public void register(RegisterBody registerBody) { |
| | | HttpServletRequest request = ServletUtils.getRequest(); |
| | | String tenantId = registerBody.getTenantId(); |
| | | String username = registerBody.getUsername(); |
| | | String password = registerBody.getPassword(); |
| | |
| | | boolean captchaEnabled = captchaProperties.getEnable(); |
| | | // 验证码开关 |
| | | if (captchaEnabled) { |
| | | validateCaptcha(tenantId, username, registerBody.getCode(), registerBody.getUuid(), request); |
| | | validateCaptcha(tenantId, username, registerBody.getCode(), registerBody.getUuid()); |
| | | } |
| | | SysUserBo sysUser = new SysUserBo(); |
| | | sysUser.setUserName(username); |
| | |
| | | sysUser.setPassword(BCrypt.hashpw(password)); |
| | | sysUser.setUserType(userType); |
| | | |
| | | if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(sysUser))) { |
| | | if (!userService.checkUserNameUnique(sysUser)) { |
| | | throw new UserException("user.register.save.error", username); |
| | | } |
| | | boolean regFlag = userService.registerUser(sysUser, tenantId); |
| | |
| | | * @param username 用户名 |
| | | * @param code 验证码 |
| | | * @param uuid 唯一标识 |
| | | * @return 结果 |
| | | */ |
| | | public void validateCaptcha(String tenantId, String username, String code, String uuid, HttpServletRequest request) { |
| | | 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); |