From 2023de973e6adb490bba962b1d830fd8e4be9418 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期五, 13 一月 2023 23:22:30 +0800 Subject: [PATCH] update 适配 新序列化注解 --- ruoyi-system/src/main/java/com/ruoyi/system/service/SysRegisterService.java | 45 ++++++++++++++++++++++++++++++++------------- 1 files changed, 32 insertions(+), 13 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 8c7274e..e0e6557 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,11 +1,12 @@ 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.event.LogininforEvent; import com.ruoyi.common.core.domain.entity.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; @@ -14,10 +15,11 @@ 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; /** * 娉ㄥ唽鏍¢獙鏂规硶 @@ -30,7 +32,6 @@ private final ISysUserService userService; private final ISysConfigService configService; - private final LogininforService asyncService; /** * 娉ㄥ唽 @@ -42,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(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")); } /** @@ -72,16 +73,34 @@ * @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) { - 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