@@ -83,7 +83,6 @@ public async Task<ActionResult<FindByUsernameResponse>> FindByEmail(string email
8383 [ ProducesResponseType ( typeof ( IdentityResult ) , StatusCodes . Status200OK ) ]
8484 [ ProducesResponseType ( typeof ( IdentityResult ) , StatusCodes . Status400BadRequest ) ]
8585 [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status500InternalServerError ) ]
86-
8786 public async Task < IActionResult > Create ( CreateUserRequest request )
8887 {
8988 try
@@ -122,6 +121,7 @@ public async Task<IActionResult> Create(CreateUserRequest request)
122121 }
123122 }
124123
124+
125125 [ HttpPost ( "activation/sendEmail" ) ]
126126 [ ProducesResponseType ( typeof ( void ) , StatusCodes . Status202Accepted ) ]
127127 [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status400BadRequest ) ]
@@ -159,5 +159,111 @@ await _metrics.UsersControllerMetrics()
159159 } ) ;
160160 }
161161 }
162+
163+ [ HttpPost ( "activation/confirm" ) ]
164+ [ ProducesResponseType ( typeof ( void ) , StatusCodes . Status202Accepted ) ]
165+ [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status404NotFound ) ]
166+ [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status401Unauthorized ) ]
167+ [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status500InternalServerError ) ]
168+ public async Task < IActionResult > ConfirmEmail ( ConfirmEmailRequest request )
169+ {
170+ try
171+ {
172+ await _metrics . UsersControllerMetrics ( )
173+ . RecordTimeToConfirmEmail ( async ( ) => await _userService . ConfirmEmail ( request ) ) ;
174+ _metrics . UsersControllerMetrics ( ) . MarkSuccessfulConfirmation ( ) ;
175+ return Accepted ( ) ;
176+ }
177+ catch ( UserNotFoundException )
178+ {
179+ _logger . LogInformation ( $ "user not found { request . Login } ") ;
180+ _metrics . UsersControllerMetrics ( ) . MarkUserNotFoundActivation ( ) ;
181+ return NotFound ( new ProblemDetails { Type = "NotFound" , Title = "user not found" } ) ;
182+ }
183+ catch ( EmailConfirmationFailedException e )
184+ {
185+ _logger . LogInformation ( "EmailConfirmationFailed" , e ) ;
186+ _metrics . UsersControllerMetrics ( ) . MarkFailedToConfirmActivation ( ) ;
187+ return Unauthorized ( new ProblemDetails { Title = "failed to confirm" } ) ;
188+ }
189+ catch ( Exception e )
190+ {
191+ _metrics . UsersControllerMetrics ( ) . MarkExceptionActivation ( e . GetType ( ) . FullName ) ;
192+ _logger . LogCritical ( e , "unexpected error during email confirmation" ) ;
193+ return StatusCode ( StatusCodes . Status500InternalServerError , new ProblemDetails
194+ {
195+ Title = "error handling request"
196+ } ) ;
197+ }
198+ }
199+
200+
201+ [ HttpPost ( "password/requestReset" ) ]
202+ [ ProducesResponseType ( typeof ( void ) , StatusCodes . Status200OK ) ]
203+ [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status404NotFound ) ]
204+ [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status500InternalServerError ) ]
205+ public async Task < IActionResult > RequestPasswordReset ( RequestPasswordReset request )
206+ {
207+ try
208+ {
209+ await _metrics . UsersControllerMetrics ( ) . MeasureTimeToSendPasswordResetEmail ( async ( ) =>
210+ await _userService . RequestPasswordReset ( request . Login ) ) ;
211+ return Accepted ( ) ;
212+ }
213+ catch ( UserNotFoundException )
214+ {
215+ _metrics . UsersControllerMetrics ( ) . MarkPasswordResetUserNotFound ( ) ;
216+ return NotFound ( new ProblemDetails
217+ {
218+ Title = "user not found"
219+ } ) ;
220+ }
221+ catch ( EmailSendingFailureException e )
222+ {
223+ _logger . LogError ( "error sending email" , e ) ;
224+ _metrics . UsersControllerMetrics ( ) . MarkEmailSendingFailure ( ) ;
225+ return StatusCode ( StatusCodes . Status500InternalServerError , new ProblemDetails
226+ {
227+ Title = "error handling request"
228+ } ) ;
229+ }
230+ }
231+
232+ [ HttpPost ( "password/reset" ) ]
233+ [ ProducesResponseType ( typeof ( void ) , StatusCodes . Status202Accepted ) ]
234+ [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status400BadRequest ) ]
235+ [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status404NotFound ) ]
236+ [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status401Unauthorized ) ]
237+ [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status500InternalServerError ) ]
238+ public async Task < IActionResult > ResetPassword ( ResetPasswordRequest request )
239+ {
240+ try
241+ {
242+ await _metrics . UsersControllerMetrics ( ) . MeasureTimeToResetPassword ( async ( ) =>
243+ await _userService . ResetPassword ( request ) ) ;
244+ return Accepted ( ) ;
245+ }
246+ catch ( UserNotFoundException e )
247+ {
248+ _logger . LogWarning ( "user not found while resetting password: " , e ) ;
249+ _metrics . UsersControllerMetrics ( ) . MarkPasswordResetUserNotFound ( ) ;
250+ return NotFound ( new ProblemDetails { Type = "NotFound" , Title = "user not found" } ) ;
251+ }
252+ catch ( PasswordResetFailedException e )
253+ {
254+ _logger . LogWarning ( "failed resetting password" , e ) ;
255+ _metrics . UsersControllerMetrics ( ) . MarkFailedToResetPassword ( ) ;
256+ return Unauthorized ( new ProblemDetails { Title = "failed to reset" } ) ;
257+ }
258+ catch ( Exception e )
259+ {
260+ _logger . LogError ( "caught exception" , e ) ;
261+ _metrics . UsersControllerMetrics ( ) . MarkResetPasswordException ( e . GetType ( ) . FullName ) ;
262+ return StatusCode ( StatusCodes . Status500InternalServerError , new ProblemDetails
263+ {
264+ Title = "error handling request"
265+ } ) ;
266+ }
267+ }
162268 }
163269}
0 commit comments