From 7d1c53f92738166c1ced1a796e2bc95d26d35fa0 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 18 一月 2023 11:59:32 +0800 Subject: [PATCH] update 优化 修改 oss 配置页面开关说明 避免造成误解 --- ruoyi-system/src/main/java/com/ruoyi/system/service/SysRegisterService.java | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 36 insertions(+), 16 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/SysRegisterService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysRegisterService.java index 5f44991..bd46055 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/SysRegisterService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysRegisterService.java @@ -1,22 +1,25 @@ 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; +import com.ruoyi.common.core.domain.event.LogininforEvent; +import com.ruoyi.system.domain.SysUser; import com.ruoyi.common.core.domain.model.RegisterBody; -import com.ruoyi.common.core.service.LogininforService; import com.ruoyi.common.enums.UserType; import com.ruoyi.common.exception.user.CaptchaException; import com.ruoyi.common.exception.user.CaptchaExpireException; import com.ruoyi.common.exception.user.UserException; import com.ruoyi.common.utils.MessageUtils; -import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.ServletUtils; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.redis.RedisUtils; +import com.ruoyi.common.utils.spring.SpringUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; /** * 娉ㄥ唽鏍¢獙鏂规硶 @@ -29,7 +32,6 @@ private final ISysUserService userService; private final ISysConfigService configService; - private final LogininforService asyncService; /** * 娉ㄥ唽 @@ -41,25 +43,25 @@ // 鏍¢獙鐢ㄦ埛绫诲瀷鏄惁瀛樺湪 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(SecurityUtils.encryptPassword(password)); + 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"); } - asyncService.recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.register.success"), request); + recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.register.success")); } /** @@ -71,16 +73,34 @@ * @return 缁撴灉 */ public void validateCaptcha(String username, String code, String uuid, HttpServletRequest request) { - String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; + String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, ""); String captcha = RedisUtils.getCacheObject(verifyKey); RedisUtils.deleteObject(verifyKey); if (captcha == null) { - asyncService.recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.expire"), request); + recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.expire")); throw new CaptchaExpireException(); } if (!code.equalsIgnoreCase(captcha)) { - asyncService.recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.error"), request); + recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.error")); throw new CaptchaException(); } } + + /** + * 璁板綍鐧诲綍淇℃伅 + * + * @param username 鐢ㄦ埛鍚� + * @param status 鐘舵�� + * @param message 娑堟伅鍐呭 + * @return + */ + private void recordLogininfor(String username, String status, String message) { + LogininforEvent logininforEvent = new LogininforEvent(); + logininforEvent.setUsername(username); + logininforEvent.setStatus(status); + logininforEvent.setMessage(message); + logininforEvent.setRequest(ServletUtils.getRequest()); + SpringUtils.context().publishEvent(logininforEvent); + } + } -- Gitblit v1.9.3