优化用户登录逻辑
This commit is contained in:
@@ -67,7 +67,7 @@ public class LoginController {
|
|||||||
@RequestParam String phone, @RequestParam String password) {
|
@RequestParam String phone, @RequestParam String password) {
|
||||||
User user = userService.getUserByPhone(phone);
|
User user = userService.getUserByPhone(phone);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return Result.error().message("User not found with phone: " + phone);
|
return Result.error().message("手机号未注册");
|
||||||
}
|
}
|
||||||
String userId = user.getUserId();
|
String userId = user.getUserId();
|
||||||
|
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ public class TencentSmsController {
|
|||||||
map.put("expireAt", expireAt);
|
map.put("expireAt", expireAt);
|
||||||
Map<String, Object> codeMap = new HashMap<>(map);
|
Map<String, Object> codeMap = new HashMap<>(map);
|
||||||
codeMap.put("code", code);
|
codeMap.put("code", code);
|
||||||
|
System.out.println(codeMap);
|
||||||
if (!sent) {
|
if (!sent) {
|
||||||
//4.保存验证码到Redis,并且设置有效期5分钟
|
//4.保存验证码到Redis,并且设置有效期5分钟
|
||||||
redisTemplate.opsForValue().set(phone, codeMap, Duration.ofMinutes(5));
|
redisTemplate.opsForValue().set(phone, codeMap, Duration.ofMinutes(5));
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class UserService implements UserDetailsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public User getUserByPhone(String phone) {
|
public User getUserByPhone(String phone) {
|
||||||
return userRepository.findUserByPhone(phone).orElseThrow(() -> new RuntimeException("User not found with phone: " + phone));
|
return userRepository.findUserByPhone(phone).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public User registerUser(String userId, String password) {
|
public User registerUser(String userId, String password) {
|
||||||
|
|||||||
Reference in New Issue
Block a user