增加同意验证,但是没有成功

This commit is contained in:
2025-08-07 10:18:28 +08:00
parent d2e479b9f8
commit ad85efaa74
7 changed files with 167 additions and 57 deletions

View File

@@ -8,10 +8,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.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/user")
@@ -30,54 +27,49 @@ public class UserPasswordController {
this.authenticationManager = authenticationManager;
}
@PostMapping("/phone_set_password")
@PostMapping("/phone_set_password")
public Result setPasswordByPhone(
HttpServletRequest request, @RequestParam(value = "user_id") String userId,
@RequestParam String password, @RequestParam(value = "verify_password") String verifyPassword,
@RequestParam(value = "device_id") String deviceId) {
String authHeader = request.getHeader("Authorization");
if (authHeader != null && authHeader.startsWith("Bearer ")) {
String token = authHeader.substring(7); // 提取真正的Token
if (StringUtils.equals(password, verifyPassword)) {
if (jwtUtil.validateAccessToken(userId, token, deviceId)) {
userService.setPasswordByUserId(userId, password);
return Result.ok().message("set password success");
} else {
return Result.error().message("token is not same");
}
} else {
return Result.error().message("password is not same");
}
} else {
@RequestHeader("Authorization") String authHeader, @RequestHeader("Device-ID") String deviceId,
@RequestParam(value = "user_id") String userId,
@RequestParam String password, @RequestParam(value = "verify_password") String verifyPassword) {
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
return Result.error().message("Authorization header is incorrect");
}
if (!StringUtils.equals(password, verifyPassword)) {
return Result.error().message("password is not same");
}
String token = authHeader.substring(7); // 提取真正的Token
if (jwtUtil.validateAccessToken(userId, token, deviceId)) {
userService.setPasswordByUserId(userId, password);
return Result.ok().message("set password success");
} else {
return Result.error().message("token is not same");
}
}
@PostMapping("/change_password")
public Result changePassword(
HttpServletRequest request,
@RequestParam(value = "user_id") String userId,
@RequestParam(value = "old_password") String oldPassword,
@RequestParam String password, @RequestParam(value = "verify_password") String verifyPassword,
@RequestParam(value = "device_id") String deviceId) {
String authHeader = request.getHeader("Authorization");
if (authHeader != null && authHeader.startsWith("Bearer ")) {
String token = authHeader.substring(7);
if (StringUtils.equals(password, verifyPassword)) {
if (!oldPassword.equals(password)) {
if (jwtUtil.validateAccessToken(userId, token, deviceId)) {
return userService.changePassword(userId, oldPassword, password);
} else {
return Result.error().message("token is not same");
}
} else {
return Result.error().message("The old password and the new password are the same");
}
} else {
return Result.error().message("password is not same");
}
} else {
@RequestHeader("Authorization") String authHeader, @RequestHeader("Device-ID") String deviceId,
@RequestParam(value = "user_id") String userId, @RequestParam(value = "old_password") String oldPassword,
@RequestParam String password, @RequestParam(value = "verify_password") String verifyPassword) {
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
return Result.error().message("Authorization header is incorrect");
}
String token = authHeader.substring(7);
if (!StringUtils.equals(password, verifyPassword)) {
return Result.error().message("password is not same");
}
if (oldPassword.equals(password)) {
return Result.error().message("The old password and the new password are the same");
}
if (jwtUtil.validateAccessToken(userId, token, deviceId)) {
return userService.changePassword(userId, oldPassword, password);
} else {
return Result.error().message("token is not same");
}
}
}