aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/src/Endpoints/Internal/PasswordResetRequests/IsResetRequestValidRoute.cs
blob: 687cef67ada48349362ab38329d46b64a2a729ee (plain) (blame)
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
namespace IOL.GreatOffice.Api.Endpoints.Internal.PasswordResetRequests;

public class IsResetRequestValidRoute : RouteBaseAsync.WithRequest<Guid>.WithActionResult
{
    private readonly PasswordResetService _passwordResetService;

    public IsResetRequestValidRoute(PasswordResetService passwordResetService) {
        _passwordResetService = passwordResetService;
    }

    /// <summary>
    /// Check if a given password reset request is still valid.
    /// </summary>
    /// <param name="id"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    [AllowAnonymous]
    [HttpGet("~/_/password-reset-request/is-valid")]
    public override async Task<ActionResult> HandleAsync(Guid id, CancellationToken cancellationToken = default) {
        var request = await _passwordResetService.GetRequestAsync(id, cancellationToken);
        if (request == default) {
            return NotFound();
        }

        return Ok(request.IsExpired == false);
    }
}