diff --git a/youlai-system/system-boot/pom.xml b/youlai-system/system-boot/pom.xml
index 3ed572c66..7f237942c 100644
--- a/youlai-system/system-boot/pom.xml
+++ b/youlai-system/system-boot/pom.xml
@@ -105,6 +105,11 @@
common-apidoc
+
+ com.youlai
+ common-sms
+
+
org.springframework.boot
diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/config/PasswordEncoderConfig.java b/youlai-system/system-boot/src/main/java/com/youlai/system/config/PasswordEncoderConfig.java
index d99e47d3b..3208d0d72 100644
--- a/youlai-system/system-boot/src/main/java/com/youlai/system/config/PasswordEncoderConfig.java
+++ b/youlai-system/system-boot/src/main/java/com/youlai/system/config/PasswordEncoderConfig.java
@@ -6,10 +6,10 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
/**
- * 密码编码器
+ * 密码编码器(修改、重置密码使用)
*
* @author haoxr
- * @since 2022/10/21
+ * @since 0.0.1
*/
@Configuration
public class PasswordEncoderConfig {
diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/controller/SysUserController.java b/youlai-system/system-boot/src/main/java/com/youlai/system/controller/SysUserController.java
index 7ee4b6e12..05b8b1800 100644
--- a/youlai-system/system-boot/src/main/java/com/youlai/system/controller/SysUserController.java
+++ b/youlai-system/system-boot/src/main/java/com/youlai/system/controller/SysUserController.java
@@ -126,8 +126,8 @@ public class SysUserController {
public Result getUserAuthInfo(
@Parameter(description = "用户名") @PathVariable String username
) {
- UserAuthInfo userAUthInfo = userService.getUserAuthInfo(username);
- return Result.success(userAUthInfo);
+ UserAuthInfo userAuthInfo = userService.getUserAuthInfo(username);
+ return Result.success(userAuthInfo);
}
@Operation(summary = "获取登录用户信息")
@@ -192,19 +192,10 @@ public class SysUserController {
@Operation(summary = "发送注册短信验证码")
@PostMapping("/register/sms_code")
- public Result sendRegisterSmsCode(
+ public Result sendRegistrationSmsCode(
@Parameter(description = "手机号") @RequestParam String mobile
) {
- boolean result = userService.sendRegisterSmsCode(mobile);
- return Result.judge(result);
- }
-
- @Operation(summary = "发送登录短信验证码")
- @PostMapping("/login/sms_code")
- public Result sendLoginSmsCode(
- @Parameter(description = "手机号") @RequestParam String mobile
- ) {
- boolean result = userService.sendLoginSmsCode(mobile);
+ boolean result = userService.sendRegistrationSmsCode(mobile);
return Result.judge(result);
}
@@ -215,4 +206,5 @@ public class SysUserController {
return Result.success(userProfile);
}
+
}
diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/service/SysUserService.java b/youlai-system/system-boot/src/main/java/com/youlai/system/service/SysUserService.java
index e72537626..4182d5966 100644
--- a/youlai-system/system-boot/src/main/java/com/youlai/system/service/SysUserService.java
+++ b/youlai-system/system-boot/src/main/java/com/youlai/system/service/SysUserService.java
@@ -124,15 +124,7 @@ public interface SysUserService extends IService {
* @param mobile 手机号
* @return {@link Boolean} 是否发送成功
*/
- boolean sendRegisterSmsCode(String mobile);
-
- /**
- * 发送登录短信验证码
- *
- * @param mobile 手机号
- * @return {@link Boolean} 是否发送成功
- */
- boolean sendLoginSmsCode(String mobile);
+ boolean sendRegistrationSmsCode(String mobile);
/**
diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysUserServiceImpl.java b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysUserServiceImpl.java
index 5b1d7d1ae..9191fdf07 100644
--- a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysUserServiceImpl.java
+++ b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysUserServiceImpl.java
@@ -15,7 +15,8 @@ import com.youlai.common.constant.RedisConstants;
import com.youlai.common.constant.SystemConstants;
import com.youlai.common.security.service.PermissionService;
import com.youlai.common.security.util.SecurityUtils;
-import com.youlai.system.config.AliyunSmsProperties;
+import com.youlai.common.sms.property.AliyunSmsProperties;
+import com.youlai.common.sms.service.SmsService;
import com.youlai.system.converter.UserConverter;
import com.youlai.system.dto.UserAuthInfo;
import com.youlai.system.mapper.SysUserMapper;
@@ -30,13 +31,13 @@ import com.youlai.system.model.vo.UserExportVO;
import com.youlai.system.model.vo.UserInfoVO;
import com.youlai.system.model.vo.UserPageVO;
import com.youlai.system.model.vo.UserProfileVO;
-import com.youlai.system.service.SmsService;
import com.youlai.system.service.SysRoleService;
import com.youlai.system.service.SysUserRoleService;
import com.youlai.system.service.SysUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -70,7 +71,7 @@ public class SysUserServiceImpl extends ServiceImpl impl
private final AliyunSmsProperties aliyunSmsProperties;
- private final RedisTemplate redisTemplate;
+ private final StringRedisTemplate redisTemplate;
/**
* 获取用户分页列表
@@ -283,7 +284,7 @@ public class SysUserServiceImpl extends ServiceImpl impl
}
});
- if (!expireTimeOpt.isPresent()) {
+ if (expireTimeOpt.isEmpty()) {
// token 永不过期则永久加入黑名单
redisTemplate.opsForValue().set(RedisConstants.TOKEN_BLACKLIST_PREFIX + jti, "");
}
@@ -303,7 +304,7 @@ public class SysUserServiceImpl extends ServiceImpl impl
String mobile = userRegisterForm.getMobile();
String code = userRegisterForm.getCode();
// 校验验证码
- String cacheCode = (String) redisTemplate.opsForValue().get(RedisConstants.REGISTER_SMS_CODE_PREFIX + mobile);
+ String cacheCode = redisTemplate.opsForValue().get(RedisConstants.REGISTER_SMS_CODE_PREFIX + mobile);
if (!StrUtil.equals(code, cacheCode)) {
log.warn("验证码不匹配或不存在: {}", mobile);
return false; // 验证码不匹配或不存在时返回false
@@ -339,7 +340,7 @@ public class SysUserServiceImpl extends ServiceImpl impl
* @return true|false 是否发送成功
*/
@Override
- public boolean sendRegisterSmsCode(String mobile) {
+ public boolean sendRegistrationSmsCode(String mobile) {
// 获取短信模板代码
String templateCode = aliyunSmsProperties.getTemplateCodes().get("register");
@@ -360,33 +361,6 @@ public class SysUserServiceImpl extends ServiceImpl impl
return result;
}
- /**
- * 发送登录短信验证码
- *
- * @param mobile 手机号
- * @return true|false 是否发送成功
- */
- @Override
- public boolean sendLoginSmsCode(String mobile) {
- // 获取短信模板代码
- String templateCode = aliyunSmsProperties.getTemplateCodes().get("login");
-
- // 生成随机4位数验证码
- String code = RandomUtil.randomNumbers(4);
-
- // 短信模板: 您的验证码:${code},该验证码5分钟内有效,请勿泄漏于他人。
- // 其中 ${code} 是模板参数,使用时需要替换为实际值。
- String templateParams = JSONUtil.toJsonStr(Collections.singletonMap("code", code));
-
- boolean result = smsService.sendSms(mobile, templateCode, templateParams);
- if (result) {
- // 将验证码存入redis,有效期5分钟
- redisTemplate.opsForValue().set(RedisConstants.REGISTER_SMS_CODE_PREFIX + mobile, code, 5, TimeUnit.MINUTES);
-
- // TODO 考虑记录每次发送短信的详情,如发送时间、手机号和短信内容等,以便后续审核或分析短信发送效果。
- }
- return result;
- }
/**
* 获取用户个人中心信息
diff --git a/youlai-system/system-boot/src/main/resources/mapper/SysUserMapper.xml b/youlai-system/system-boot/src/main/resources/mapper/SysUserMapper.xml
index 06f4b25be..301f11372 100644
--- a/youlai-system/system-boot/src/main/resources/mapper/SysUserMapper.xml
+++ b/youlai-system/system-boot/src/main/resources/mapper/SysUserMapper.xml
@@ -23,7 +23,7 @@
LEFT JOIN sys_user_role sur ON u.id = sur.user_id
LEFT JOIN sys_role r ON sur.role_id = r.id
- u.deleted = 0 AND u.username != ${@com.youlai.common.constant.SystemConstants@ROOT_ROLE_CODE}
+ u.deleted = 0 AND u.username != '${@com.youlai.common.constant.SystemConstants@ROOT_ROLE_CODE}'
AND (
u.username LIKE CONCAT('%',#{queryParams.keywords},'%')
@@ -74,17 +74,21 @@
dept_id
FROM
sys_user
- WHERE id = #{userId}
- AND deleted = 0
+ WHERE
+ id = #{userId} AND deleted = 0
-
-
-
-
-
+
+
+
+
+
+
+
+
+
@@ -93,13 +97,16 @@