Bläddra i källkod

修改短信发送规则(宽松)

Mure 3 veckor sedan
förälder
incheckning
ec104da404

+ 12 - 4
src/main/java/com/backendsys/modules/material/service/impl/MaterialUserServiceImpl.java

@@ -172,7 +172,7 @@ public class MaterialUserServiceImpl implements MaterialUserService {
 
         // 判断短信验证码是否正确
         if (!"local".equals(activeProfile)) {
-            String redisKey = APPLICATION_NAME + "-sms-register" + "-" + phone;
+            String redisKey = APPLICATION_NAME + "-sms-" + phone;
             Integer smsCode = redisUtil.getCacheObject(redisKey);
             // 判断是否发送验证码
             if ("false".equals(SMS_DEBUG) && smsCode == null) throw new CustException("请先发送短信验证码");
@@ -188,9 +188,12 @@ public class MaterialUserServiceImpl implements MaterialUserService {
         if (sysUserDetail != null) {
             // [已注册] 返回登录信息 (并且7天免登录)
             SysUserInfo sysUserInfo = sysAuthService.loginSuccess(sysUserDetail.getId(), 1);
-            return BeanUtil.beanToMap(sysUserInfo);
+            Map<String, Object> response = BeanUtil.beanToMap(sysUserInfo);
+            response.put("is_register", false);
+            return response;
+            //
         } else {
-            // [未注册] 通过校验,并注册
+            // [未注册] 通过校验并注册 (注册成功后,返回登录信息)
 
             // 注册
             SysUserDTO registerEntity = new SysUserDTO();
@@ -217,7 +220,12 @@ public class MaterialUserServiceImpl implements MaterialUserService {
             // 初始化用户积分
             sysUserIntegralService.init(registerEntity.getId());
 
-            return Map.of("user_id", registerEntity.getId());
+            // [DB] 查询用户信息
+            SysUserInfo sysUserInfo = sysAuthService.loginSuccess(registerEntity.getId(), 1);
+            Map<String, Object> response = BeanUtil.beanToMap(sysUserInfo);
+            response.put("is_register", true);
+            return response;
+
         }
     }
 }

+ 1 - 1
src/main/java/com/backendsys/modules/sms/entity/Sms.java

@@ -14,7 +14,7 @@ public class Sms {
     public static interface Send{}
     private Long id;
     @RangeStringArray(message="短信类型有误,范围应是(login:登录, register:注册, forgotPassword: 忘记密码)", value = {"login", "register", "forgotPassword"}, groups = { Send.class })
-    @NotEmpty(message="短信类型不能为空", groups = { Send.class })
+    //@NotEmpty(message="短信类型不能为空", groups = { Send.class })
     private String origin;
     @NotEmpty(message="手机号码不能为空", groups = { Send.class })
     @Size(max = 20, message = "手机号码长度不超过 {max} 字符", groups = { Send.class })

+ 4 - 1
src/main/java/com/backendsys/modules/sms/service/impl/SmsServiceImpl.java

@@ -2,6 +2,7 @@ package com.backendsys.modules.sms.service.impl;
 
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.backendsys.exception.CustException;
@@ -86,7 +87,9 @@ public class SmsServiceImpl implements com.backendsys.modules.sms.service.SmsSer
 
         // -- 发送成功 --------------------------------------------------
         // [Redis] 将 来源+手机号码 为标识,将验证码存入缓存
-        String redisKey = APPLICATION_NAME + "-sms-" + origin + "-" + phone;
+        String originStr = StrUtil.isNotBlank(origin) ? (origin + "-") : "";
+        String redisKey = APPLICATION_NAME + "-sms-" + originStr + phone;
+
         redisUtil.setCacheObject(redisKey, smsCode, smsExpire, TimeUnit.MINUTES);
 
         // [插入] 新增短信记录

+ 2 - 0
src/main/java/com/backendsys/modules/system/service/impl/SysAuthServiceImpl.java

@@ -26,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.cache.annotation.Cacheable;
 import org.springframework.core.env.Environment;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
@@ -120,6 +121,7 @@ public class SysAuthServiceImpl implements SysAuthService {
     }
 
     @Override
+    @Cacheable(value = "catch::mobile-area", key = "'list'", unless = "#result == null")
     public List<SysMobileArea> getMobileAreaList(SysMobileArea sysMobileArea) {
         return sysMobileAreaDao.selectMobileAreaList(sysMobileArea);
     }