11package com .park .utmstack .web .rest ;
22
33
4+ import com .park .utmstack .aop .logging .AuditEvent ;
5+ import com .park .utmstack .aop .logging .Loggable ;
46import com .park .utmstack .domain .User ;
57import com .park .utmstack .domain .application_events .enums .ApplicationEventType ;
68import com .park .utmstack .repository .UserRepository ;
@@ -70,7 +72,7 @@ public ResponseEntity<String> isAuthenticated(HttpServletRequest request) {
7072 log .error (msg );
7173 applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
7274 return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).headers (
73- HeaderUtil .createFailureAlert ("" , "" , msg )).body (null );
75+ HeaderUtil .createFailureAlert ("" , "" , msg )).body (null );
7476 }
7577 }
7678
@@ -85,8 +87,8 @@ public UserDTO getAccount() {
8587 final String ctx = CLASSNAME + ".getAccount" ;
8688 try {
8789 return userService .getUserWithAuthorities ()
88- .map (UserDTO ::new )
89- .orElseThrow (() -> new InternalServerErrorException ("User could not be found" ));
90+ .map (UserDTO ::new )
91+ .orElseThrow (() -> new InternalServerErrorException ("User could not be found" ));
9092 } catch (InternalServerErrorException e ) {
9193 String msg = ctx + ": " + e .getMessage ();
9294 log .error (msg );
@@ -116,7 +118,7 @@ public void saveAccount(@Valid @RequestBody UserDTO userDTO) {
116118 throw new InternalServerErrorException ("User could not be found" );
117119
118120 userService .updateUser (userDTO .getFirstName (), userDTO .getLastName (), userDTO .getEmail (),
119- userDTO .getLangKey (), userDTO .getImageUrl ());
121+ userDTO .getLangKey (), userDTO .getImageUrl ());
120122 } catch (Exception e ) {
121123 String msg = ctx + ": " + e .getMessage ();
122124 log .error (msg );
@@ -156,8 +158,8 @@ public void requestPasswordReset(@RequestBody String mail) {
156158 final String ctx = CLASSNAME + ".requestPasswordReset" ;
157159 try {
158160 mailService .sendPasswordResetMail (
159- userService .requestPasswordReset (mail )
160- .orElseThrow (EmailNotFoundException ::new ));
161+ userService .requestPasswordReset (mail )
162+ .orElseThrow (EmailNotFoundException ::new ));
161163 } catch (Exception e ) {
162164 String msg = ctx + ": " + e .getMessage ();
163165 log .error (msg );
@@ -166,34 +168,23 @@ public void requestPasswordReset(@RequestBody String mail) {
166168 }
167169 }
168170
169- /**
170- * POST /account/reset-password/finish : Finish to reset the password of the user
171- *
172- * @param keyAndPassword the generated key and the new password
173- * @throws InvalidPasswordException 400 (Bad Request) if the password is incorrect
174- * @throws RuntimeException 500 (Internal Server Error) if the password could not be reset
175- */
171+ @ AuditEvent (
172+ attemptType = ApplicationEventType .RESET_USER_PASSWORD_ATTEMPT ,
173+ attemptMessage = "Attempt to reset user password initiated" ,
174+ successType = ApplicationEventType .RESET_USER_PASSWORD_SUCCESS ,
175+ successMessage = "User password reset successfully"
176+ )
176177 @ PostMapping (path = "/account/reset-password/finish" )
177178 public void finishPasswordReset (@ RequestBody KeyAndPasswordVM keyAndPassword ) {
178- final String ctx = CLASSNAME + ".finishPasswordReset" ;
179- try {
180- validatePasswordLength (keyAndPassword .getNewPassword ());
181- Optional <User > user =
182- userService .completePasswordReset (keyAndPassword .getNewPassword (), keyAndPassword .getKey ());
183179
184- if (user .isEmpty ())
185- throw new InternalServerErrorException ("No user was found for this reset key" );
186- } catch (Exception e ) {
187- String msg = ctx + ": " + e .getMessage ();
188- log .error (msg );
189- applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
190- throw new RuntimeException (msg );
191- }
180+ validatePasswordLength (keyAndPassword .getNewPassword ());
181+ userService .completePasswordReset (keyAndPassword .getNewPassword (), keyAndPassword .getKey ());
182+
192183 }
193184
194185 private void validatePasswordLength (String password ) {
195186 if (!StringUtils .hasText (password ) || password .length () < ManagedUserVM .PASSWORD_MIN_LENGTH ||
196- password .length () > ManagedUserVM .PASSWORD_MAX_LENGTH )
187+ password .length () > ManagedUserVM .PASSWORD_MAX_LENGTH )
197188 throw new InvalidPasswordException ();
198189 }
199190}
0 commit comments