This repository was archived by the owner on Dec 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserController.java
More file actions
42 lines (36 loc) · 1.58 KB
/
Copy pathUserController.java
File metadata and controls
42 lines (36 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.fin.spr.auth;
import com.fin.spr.controllers.payload.security.AuthenticationPayload;
import com.fin.spr.controllers.payload.security.ChangePasswordPayload;
import com.fin.spr.controllers.payload.security.RegistrationPayload;
import com.fin.spr.services.security.AuthenticationService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/auth")
public class UserController {
private final AuthenticationService authenticationService;
@PostMapping("/register")
public JwtAuthenticationResponse register(@RequestBody RegistrationPayload registrationRequest) {
return authenticationService.register(registrationRequest);
}
@PostMapping("/login")
public JwtAuthenticationResponse login(@RequestBody AuthenticationPayload authenticationPayload) {
return authenticationService.login(authenticationPayload);
}
@PostMapping("/logout")
public ResponseEntity<Void> logout(Authentication authentication) {
authenticationService.logout(authentication);
return ResponseEntity.ok().build();
}
@PatchMapping("change-password")
public ResponseEntity<Void> changePassword(
@RequestBody ChangePasswordPayload changePasswordRequest,
Authentication authentication
) {
authenticationService.changePassword(changePasswordRequest, authentication);
return ResponseEntity.ok().build();
}
}