修复一分钟之内获取验证码问题,优化设置密码

This commit is contained in:
2025-09-04 09:23:46 +08:00
parent 06186c669e
commit 5d16ba01bd
2 changed files with 7 additions and 6 deletions

View File

@@ -173,10 +173,8 @@ public class TencentSmsController {
Map<String, Object> codeMap = new HashMap<>(map);
codeMap.put("code", code);
logger.info(codeMap.toString());
if (!sent) {
//4.保存验证码到Redis,并且设置有效期5分钟
redisTemplate.opsForValue().set(phone, codeMap, Duration.ofMinutes(5));
}
//4.保存验证码到Redis,并且设置有效期5分钟
redisTemplate.opsForValue().set(phone, codeMap, Duration.ofMinutes(5));
return Result.ok().data(map);
} else {
return Result.error().message("短信发送失败");

View File

@@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;
@RestController
@@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
public class UserPasswordController {
private final UserService userService;
private final AuthenticationManager authenticationManager;
private final PasswordEncoder passwordEncoder;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@@ -24,9 +26,10 @@ public class UserPasswordController {
private JwtUtil jwtUtil;
@Autowired
public UserPasswordController(UserService userService, AuthenticationManager authenticationManager) {
public UserPasswordController(UserService userService, AuthenticationManager authenticationManager,PasswordEncoder passwordEncoder) {
this.userService = userService;
this.authenticationManager = authenticationManager;
this.passwordEncoder = passwordEncoder;
}
@PostMapping("/set_first_password")
@@ -130,7 +133,7 @@ public class UserPasswordController {
return Result.error().message("password is not same");
}
user.setPassword(password);
user.setPassword(passwordEncoder.encode(password));
if (!TextUtils.isEmpty(nickName)) {
user.setNickname(nickName);