Skip to content

Commit

Permalink
add dont create OTP when email is already confirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
emrecoskun705 committed Sep 16, 2023
1 parent b8361f8 commit 3b4de0e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Unitagram.Application.Exceptions;

public class EmailAlreadyConfirmedException : Exception
{
public EmailAlreadyConfirmedException() : base("Email is already confirmed.")
{

}
}
6 changes: 6 additions & 0 deletions Unitagram.Identity/Services/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ public async Task<Result<GenerateOtpResponse>> GenerateOtpEmail(GenerateOtpReque
return new Result<GenerateOtpResponse>(exception);
}

if (user.EmailConfirmed)
{
var exception = new EmailAlreadyConfirmedException();
return new Result<GenerateOtpResponse>(exception);
}

var generateOtpResult = await _verificationService.GenerateAsync(user.Id);

var result = generateOtpResult.Match<Result<GenerateOtpResponse>>(
Expand Down
3 changes: 2 additions & 1 deletion Unitagram.WebAPI/Controllers/ControllerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ private static ActionResult<TResult> HandleException<TResult>(Exception exceptio
{ typeof(InvalidAccountCredentialsException), StatusCodes.Status400BadRequest },
{ typeof(AccountLockoutException), StatusCodes.Status403Forbidden },
{ typeof(NotFoundException), StatusCodes.Status404NotFound },
{ typeof(UserNotFoundException), StatusCodes.Status404NotFound }
{ typeof(UserNotFoundException), StatusCodes.Status404NotFound },
{ typeof(EmailAlreadyConfirmedException), StatusCodes.Status400BadRequest },
};

// Get the status code from the dictionary, defaulting to 500 if not found
Expand Down

0 comments on commit 3b4de0e

Please sign in to comment.