ResetPassword.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using MediatR;
  2. using Web.Api.Extensions;
  3. using Web.Api.Common;
  4. namespace Web.Api.Endpoints.Auth;
  5. internal sealed class ResetPassword : IEndpoint
  6. {
  7. public sealed record Request(string Email, string Password);
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapPost("api/auth/reset-password", async (
  11. Request request,
  12. HttpContext httpContext,
  13. ISender sender,
  14. CancellationToken ct
  15. ) =>
  16. {
  17. // 사전 비밀번호 재설정 검증 여부
  18. var cookieName = $"isVerified-ForgotPassword";
  19. var cookieValue = httpContext.Request.Cookies[cookieName] ?? string.Empty;
  20. var command = new Application.Features.Api.Auth.ResetPassword.Command(
  21. request.Email,
  22. request.Password,
  23. cookieValue
  24. );
  25. var result = await sender.Send(command, ct);
  26. if (result.IsSuccess)
  27. {
  28. // 인증 쿠키 삭제
  29. httpContext.Response.Cookies.Delete(cookieName);
  30. }
  31. return result.Match(
  32. () => ApiResponse.Ok(new {
  33. message = "비밀번호가 변경되었습니다."
  34. }),
  35. CustomResults.Problem
  36. );
  37. })
  38. .WithTags("Auth")
  39. .AllowAnonymous();
  40. }
  41. }