主备迁移只webflux
This commit is contained in:
@@ -5,7 +5,6 @@ import com.onekeycall.videotablet.entity.User;
|
||||
import com.onekeycall.videotablet.result.Result;
|
||||
import com.onekeycall.videotablet.service.UserService;
|
||||
import com.onekeycall.videotablet.utils.JwtUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@@ -15,14 +14,12 @@ import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/public")
|
||||
public class LoginController {
|
||||
|
||||
private final UserService userService;
|
||||
@@ -39,7 +36,7 @@ public class LoginController {
|
||||
this.authenticationManager = authenticationManager;
|
||||
}
|
||||
|
||||
@PostMapping("/public/register")
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<?> registerUser(@RequestBody RegisterRequest registerRequest) {
|
||||
try {
|
||||
userService.registerUser(registerRequest.getUsername(), registerRequest.getPassword());
|
||||
@@ -49,7 +46,7 @@ public class LoginController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/public/login")
|
||||
@PostMapping("/login")
|
||||
public ResponseEntity<?> login(
|
||||
@RequestParam(value = "user_id") String userId, @RequestParam String password,
|
||||
@RequestParam(value = "device_id", required = false) String deviceId) {
|
||||
@@ -91,7 +88,7 @@ public class LoginController {
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/public/registerByPhone")
|
||||
@PostMapping("/phone_register")
|
||||
public Result registerByPhone(
|
||||
@RequestParam String phone, @RequestParam String code,
|
||||
@RequestParam(value = "verify_key") String verifyKey, @RequestParam(value = "device_id") String deviceId) {
|
||||
@@ -129,7 +126,7 @@ public class LoginController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/public/loginByPhone")
|
||||
@PostMapping("/phone_login")
|
||||
public Result loginByPhone(
|
||||
@RequestParam String phone, @RequestParam String code,
|
||||
@RequestParam(value = "verify_key") String verifyKey, @RequestParam(value = "device_id") String deviceId) {
|
||||
@@ -161,54 +158,5 @@ public class LoginController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/public/setPasswordByPhone")
|
||||
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 {
|
||||
return Result.error().message("Authorization header is incorrect");
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/public/changePassword")
|
||||
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 {
|
||||
return Result.error().message("Authorization header is incorrect");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user