适配JwtVerify注释

This commit is contained in:
高子兴 2024-07-02 02:25:42 +08:00
parent 3641689cbb
commit ad14782702
4 changed files with 11 additions and 21 deletions

View File

@ -2,6 +2,7 @@ package org.cmh.backend.authentication.controller;
import org.cmh.backend.Utils.JwtUtil;
import org.cmh.backend.Utils.JwtVerify;
import org.cmh.backend.authentication.dto.*;
import org.cmh.backend.authentication.model.UserHS;
import org.cmh.backend.authentication.service.UserService;
@ -75,23 +76,21 @@ class AuthenticationController {
}
@PostMapping("/manageUserProfile")
@JwtVerify
public ResponseEntity<Object> manageUserProfile(@RequestBody ManageUserProfileRequest userProfileRequest) {
String username = JwtUtil.extractUsername(userProfileRequest.getToken());
if (username != null) {
boolean succeeded = userService.updateUserProfile(username, userProfileRequest);
if (succeeded) {
return new ResponseEntity<>(HttpStatus.OK);
}
boolean succeeded = userService.updateUserProfile(username, userProfileRequest);
if (succeeded) {
return new ResponseEntity<>(HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
@PostMapping("/changePassword")
@JwtVerify
public ResponseEntity<Object> changePassword(@RequestBody ChangePasswordRequest changePasswordRequest) {
if (JwtUtil.isTokenValid(changePasswordRequest.getToken())) {
if (userService.changePassword(JwtUtil.extractUsername(changePasswordRequest.getToken()), changePasswordRequest)) {
return new ResponseEntity<>(HttpStatus.OK);
}
if (userService.changePassword(JwtUtil.extractUsername(changePasswordRequest.getToken()), changePasswordRequest)) {
return new ResponseEntity<>(HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}

View File

@ -2,10 +2,11 @@ package org.cmh.backend.authentication.dto;
import lombok.Getter;
import lombok.Setter;
import org.cmh.backend.Utils.JwtRequest;
@Getter
@Setter
public class ChangePasswordRequest extends JwtRequest{
public class ChangePasswordRequest extends JwtRequest {
private String currentPassword;
private String newPassword;
}

View File

@ -1,11 +0,0 @@
package org.cmh.backend.authentication.dto;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class JwtRequest {
private String token;
}

View File

@ -2,6 +2,7 @@ package org.cmh.backend.authentication.dto;
import lombok.Getter;
import lombok.Setter;
import org.cmh.backend.Utils.JwtRequest;
@Getter
@Setter