| | |
| | | package com.ruoyi.system.service; |
| | | |
| | | import cn.dev33.satoken.secure.BCrypt; |
| | | import com.ruoyi.common.constant.CacheConstants; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | |
| | | // 校验用户类型是否存在 |
| | | String userType = UserType.getUserType(registerBody.getUserType()).getUserType(); |
| | | |
| | | boolean captchaOnOff = configService.selectCaptchaOnOff(); |
| | | boolean captchaEnabled = configService.selectCaptchaEnabled(); |
| | | // 验证码开关 |
| | | if (captchaOnOff) { |
| | | if (captchaEnabled) { |
| | | validateCaptcha(username, registerBody.getCode(), registerBody.getUuid(), request); |
| | | } |
| | | |
| | | if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username))) { |
| | | throw new UserException("user.register.save.error", username); |
| | | } |
| | | SysUser sysUser = new SysUser(); |
| | | sysUser.setUserName(username); |
| | | sysUser.setNickName(username); |
| | | sysUser.setPassword(BCrypt.hashpw(password)); |
| | | sysUser.setUserType(userType); |
| | | |
| | | if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(sysUser))) { |
| | | throw new UserException("user.register.save.error", username); |
| | | } |
| | | boolean regFlag = userService.registerUser(sysUser); |
| | | if (!regFlag) { |
| | | throw new UserException("user.register.error"); |
| | |
| | | * @return 结果 |
| | | */ |
| | | public void validateCaptcha(String username, String code, String uuid, HttpServletRequest request) { |
| | | String verifyKey = Constants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, ""); |
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, ""); |
| | | String captcha = RedisUtils.getCacheObject(verifyKey); |
| | | RedisUtils.deleteObject(verifyKey); |
| | | if (captcha == null) { |