修复一分钟之内获取验证码问题,优化设置密码
This commit is contained in:
@@ -173,10 +173,8 @@ public class TencentSmsController {
|
|||||||
Map<String, Object> codeMap = new HashMap<>(map);
|
Map<String, Object> codeMap = new HashMap<>(map);
|
||||||
codeMap.put("code", code);
|
codeMap.put("code", code);
|
||||||
logger.info(codeMap.toString());
|
logger.info(codeMap.toString());
|
||||||
if (!sent) {
|
//4.保存验证码到Redis,并且设置有效期5分钟
|
||||||
//4.保存验证码到Redis,并且设置有效期5分钟
|
redisTemplate.opsForValue().set(phone, codeMap, Duration.ofMinutes(5));
|
||||||
redisTemplate.opsForValue().set(phone, codeMap, Duration.ofMinutes(5));
|
|
||||||
}
|
|
||||||
return Result.ok().data(map);
|
return Result.ok().data(map);
|
||||||
} else {
|
} else {
|
||||||
return Result.error().message("短信发送失败");
|
return Result.error().message("短信发送失败");
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
public class UserPasswordController {
|
public class UserPasswordController {
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final AuthenticationManager authenticationManager;
|
private final AuthenticationManager authenticationManager;
|
||||||
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
@@ -24,9 +26,10 @@ public class UserPasswordController {
|
|||||||
private JwtUtil jwtUtil;
|
private JwtUtil jwtUtil;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public UserPasswordController(UserService userService, AuthenticationManager authenticationManager) {
|
public UserPasswordController(UserService userService, AuthenticationManager authenticationManager,PasswordEncoder passwordEncoder) {
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.authenticationManager = authenticationManager;
|
this.authenticationManager = authenticationManager;
|
||||||
|
this.passwordEncoder = passwordEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/set_first_password")
|
@PostMapping("/set_first_password")
|
||||||
@@ -130,7 +133,7 @@ public class UserPasswordController {
|
|||||||
return Result.error().message("password is not same");
|
return Result.error().message("password is not same");
|
||||||
}
|
}
|
||||||
|
|
||||||
user.setPassword(password);
|
user.setPassword(passwordEncoder.encode(password));
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(nickName)) {
|
if (!TextUtils.isEmpty(nickName)) {
|
||||||
user.setNickname(nickName);
|
user.setNickname(nickName);
|
||||||
|
|||||||
Reference in New Issue
Block a user