/userProfile完成
This commit is contained in:
parent
0f13440ab0
commit
aa9e0d8804
@ -12,6 +12,8 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
class AuthenticationController {
|
class AuthenticationController {
|
||||||
|
|
||||||
@ -51,15 +53,25 @@ class AuthenticationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/userProfile")
|
@GetMapping("/userProfile")
|
||||||
public ResponseEntity<UserHS> getUserProfile(@RequestParam String jwt) {
|
public ResponseEntity<UserProfileResponse> getUserProfile(@RequestParam String token) {
|
||||||
UserHS user = userService.getUserByUsername(JwtUtil.);
|
if (JwtUtil.isTokenValid(token)) {
|
||||||
if (user != null) {
|
UserHS user = userService.getUserByUsername(JwtUtil.extractUsername(token));
|
||||||
return new ResponseEntity<>(user, HttpStatus.OK);
|
if (user != null) {
|
||||||
} else {
|
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return new ResponseEntity<>(new UserProfileResponse(
|
||||||
|
user.getUsername(),
|
||||||
|
user.getNickname(),
|
||||||
|
user.getGender(),
|
||||||
|
user.getPhoneNumber(),
|
||||||
|
user.getEmail(),
|
||||||
|
user.getDepartment(),
|
||||||
|
user.getRole(),
|
||||||
|
user.getCreatedAt()
|
||||||
|
), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -95,3 +107,17 @@ class LoginResponse {
|
|||||||
private String message;
|
private String message;
|
||||||
private String jwt;
|
private String jwt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
class UserProfileResponse {
|
||||||
|
private String username;
|
||||||
|
private String nickname;
|
||||||
|
private String gender;
|
||||||
|
private String phoneNumber;
|
||||||
|
private String email;
|
||||||
|
private String department;
|
||||||
|
private String role;
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user