added OtpRequestDTO to fix RequestBody for @PostMapping("/request-otp-for-password-reset")
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
+74
-11
@@ -249,6 +249,16 @@ paths:
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
/notifications/unregister-device-token:
|
||||
put:
|
||||
tags:
|
||||
- notification-controller
|
||||
description: Unregisters the device token for push notifications for the authenticated
|
||||
user.
|
||||
operationId: unregisterDeviceToken
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
/notifications/register-device-token:
|
||||
put:
|
||||
tags:
|
||||
@@ -633,6 +643,49 @@ paths:
|
||||
responses:
|
||||
"200":
|
||||
description: Check successful
|
||||
/auth/user/reset-password:
|
||||
post:
|
||||
tags:
|
||||
- user-authentication-controller
|
||||
summary: 'Veränderung des Passworts eines Profils '
|
||||
description: Durch Eingabe eines Validen OTP Codes zu einer zugehörigen Email
|
||||
kann das Passwort des Profils geändert werden.
|
||||
operationId: handlePasswordResetRequest
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/PasswordResetDTO"
|
||||
required: true
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'*/*':
|
||||
schema:
|
||||
type: string
|
||||
/auth/user/request-password-reset:
|
||||
post:
|
||||
tags:
|
||||
- user-authentication-controller
|
||||
summary: OTP Code zur änderung des Passworts
|
||||
description: "Erstellt bei Anfrage einen neuen 6-stelligen OTP Code, mit welchem\
|
||||
\ das Passwort des Accounts mit der zugehörigen Email einmalig verändert werden\
|
||||
\ kann. Dieser wird per Mail an den Nutzer gesendet."
|
||||
operationId: handleForgotPasswordRequest
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'*/*':
|
||||
schema:
|
||||
type: string
|
||||
/auth/user/registration:
|
||||
post:
|
||||
tags:
|
||||
@@ -1757,15 +1810,15 @@ components:
|
||||
description: The temporal difference in minutes compared to the original
|
||||
route (in case alternative was requested) / the car route (when simply
|
||||
directions requested) .
|
||||
cyclingRoute:
|
||||
type: boolean
|
||||
walkingRoute:
|
||||
type: boolean
|
||||
physicalActivity:
|
||||
type: boolean
|
||||
durationSeconds:
|
||||
type: integer
|
||||
format: int64
|
||||
walkingRoute:
|
||||
type: boolean
|
||||
cyclingRoute:
|
||||
type: boolean
|
||||
physicalActivity:
|
||||
type: boolean
|
||||
StepDTO:
|
||||
type: object
|
||||
description: A single step within a suggested alternative route.
|
||||
@@ -1838,6 +1891,15 @@ components:
|
||||
- destinationLon
|
||||
- originLat
|
||||
- originLon
|
||||
PasswordResetDTO:
|
||||
type: object
|
||||
properties:
|
||||
otp_code:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
new_password:
|
||||
type: string
|
||||
UserRegistrationDTO:
|
||||
type: object
|
||||
properties:
|
||||
@@ -1869,6 +1931,7 @@ components:
|
||||
- EMAIL_INVALID
|
||||
- PUBLIC_NAME_EXISTS
|
||||
- PUBLIC_NAME_FORBIDDEN
|
||||
- PASSWORD_INVALID
|
||||
- UNKNOWN_ERROR
|
||||
UserAuthenticationPairDTO:
|
||||
type: object
|
||||
@@ -1886,10 +1949,7 @@ components:
|
||||
km_PUBLIC_TRANSPORT:
|
||||
type: integer
|
||||
format: int64
|
||||
mobility_SCORE:
|
||||
type: integer
|
||||
format: int64
|
||||
co2_SAVED:
|
||||
xp:
|
||||
type: integer
|
||||
format: int64
|
||||
km_CYCLED:
|
||||
@@ -1901,7 +1961,10 @@ components:
|
||||
km_DRIVEN:
|
||||
type: integer
|
||||
format: int64
|
||||
xp:
|
||||
mobility_SCORE:
|
||||
type: integer
|
||||
format: int64
|
||||
co2_SAVED:
|
||||
type: integer
|
||||
format: int64
|
||||
StatsList:
|
||||
|
||||
@@ -3,9 +3,7 @@ package SuMoC.backend.security.controller;
|
||||
|
||||
import SuMoC.backend.security.dtos.*;
|
||||
import SuMoC.backend.security.exceptions.InvalidTokenException;
|
||||
import SuMoC.backend.security.models.PasswordResetToken;
|
||||
import SuMoC.backend.security.services.AuthenticationService;
|
||||
import SuMoC.backend.user.repository.UserRepository;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -21,8 +19,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/auth/user")
|
||||
public class UserAuthenticationController {
|
||||
@@ -82,39 +78,33 @@ public class UserAuthenticationController {
|
||||
@Operation(summary = "OTP Code zur änderung des Passworts", description = "Erstellt bei Anfrage einen neuen 6-stelligen OTP Code, " +
|
||||
"mit welchem das Passwort des Accounts mit der zugehörigen Email einmalig verändert werden kann." +
|
||||
" Dieser wird per Mail an den Nutzer gesendet.")
|
||||
@PostMapping("/request-password-reset")
|
||||
public ResponseEntity<String> handleForgotPasswordRequest(@RequestBody String email, Principal principal){
|
||||
System.out.println("####################### Handle Password Reset Request #######################");
|
||||
System.out.println(email);
|
||||
@PostMapping("/request-otp-for-password-reset")
|
||||
public ResponseEntity<String> requestOtpForPasswordReset(@RequestBody OtpRequestDTO otpRequestDTO) {
|
||||
|
||||
try{
|
||||
authenticationService.generateNewPasswordResetTokenForUser(email);
|
||||
return ResponseEntity.ok("OTP Token erstellt");
|
||||
authenticationService.generateNewPasswordResetTokenForUser(otpRequestDTO.getEmail());
|
||||
return ResponseEntity.ok("OTP erstellt");
|
||||
} catch (UsernameNotFoundException e) {
|
||||
return ResponseEntity.badRequest().body(e.getMessage());
|
||||
} catch(MailException e){
|
||||
System.out.println(" ## MAIL EXCEPTION \n" +e.getMessage());
|
||||
return ResponseEntity.internalServerError().body("Fehler beim versenden der Email, versuche es später erneut");
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.internalServerError().body("Fehler beim erstellen des OTP Tokens");
|
||||
return ResponseEntity.internalServerError().body("Fehler beim erstellen des OTP");
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "Veränderung des Passworts eines Profils ", description = "Durch Eingabe eines Validen OTP Codes " +
|
||||
"zu einer zugehörigen Email kann das Passwort des Profils geändert werden.")
|
||||
@PostMapping("/reset-password")
|
||||
public ResponseEntity<String> handlePasswordResetRequest(@RequestBody PasswordResetDTO passwordResetDTO){
|
||||
System.out.println("####################### Handle Password Reset Request RESET #######################");
|
||||
|
||||
System.out.println(passwordResetDTO.getEmail() + " | newPW: " + passwordResetDTO.getNew_password() + " | Code: " + passwordResetDTO.getOtp_code());
|
||||
public ResponseEntity<String> resetPassword(@RequestBody PasswordResetDTO passwordResetDTO){
|
||||
try {
|
||||
authenticationService.resetPassword(passwordResetDTO);
|
||||
return ResponseEntity.ok("Passwort erfolgreich geändert");
|
||||
} catch (InvalidTokenException | UsernameNotFoundException e) {
|
||||
// 400 Bad Request mit der genauen Fehlermeldung
|
||||
return ResponseEntity.badRequest().body(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Fehler beim Reset");
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Fehler beim Zurücksetzen des Passworts");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package SuMoC.backend.security.dtos;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class OtpRequestDTO {
|
||||
String email;
|
||||
}
|
||||
Reference in New Issue
Block a user