Beispiel #1
0
        public async Task <ApiResponse <ResendEmailConfirmationUserVM> > ResendEmailConfirmationAsync(ResendEmailConfirmationUserVM userToResendEmailConfirmation)
        {
            try
            {
                var successMessage = $"Confirmation email has been sent to: \"{userToResendEmailConfirmation.Email}\" if there is an account associated with it";
                userToResendEmailConfirmation.ReturnUrl += $"?email={userToResendEmailConfirmation.Email}";
                var emailReturnUrl = $"{ConfigUtils.FrontendBaseUrl}Account/Login";
                var user           = await _userManager.FindByEmailAsync(userToResendEmailConfirmation.Email);

                if (user == null)
                {
                    return(new ApiResponse <ResendEmailConfirmationUserVM>(StatusCodeType.Status200OK, successMessage, null, userToResendEmailConfirmation));
                }

                if (await _userManager.IsEmailConfirmedAsync(user))
                {
                    userToResendEmailConfirmation.ReturnUrl = emailReturnUrl;
                    return(new ApiResponse <ResendEmailConfirmationUserVM>(StatusCodeType.Status200OK, $"Email \"{userToResendEmailConfirmation.Email}\" has already been confirmed", null, userToResendEmailConfirmation));
                }

                var code = (await _userManager.GenerateEmailConfirmationTokenAsync(user)).UTF8ToBase64SafeUrl();
                var resendingConfirmationEmailResponse = await _emailSender.SendConfirmationEmailAsync(userToResendEmailConfirmation.Email, code, emailReturnUrl);

                if (resendingConfirmationEmailResponse.IsError)
                {
                    return(new ApiResponse <ResendEmailConfirmationUserVM>(StatusCodeType.Status500InternalServerError, "Can't resend Confirmation Email. Please try again later.", null, null, resendingConfirmationEmailResponse.ResponseException));
                }

                return(new ApiResponse <ResendEmailConfirmationUserVM>(StatusCodeType.Status200OK, successMessage, null, _mapper.Map(user, userToResendEmailConfirmation)));
            }
            catch (Exception ex)
            {
                return(new ApiResponse <ResendEmailConfirmationUserVM>(StatusCodeType.Status500InternalServerError, "Resending Email Confirmation Failed", null, null, ex));
            }
        }
Beispiel #2
0
 public async Task <ApiResponse <ResendEmailConfirmationUserVM> > ResendEmailConfirmationAsync(ResendEmailConfirmationUserVM resendEmailConfirmationUser)
 {
     try
     {
         return(await _httpClient.PostJTokenAsync <ApiResponse <ResendEmailConfirmationUserVM> >("api/account/resendemailconfirmation", resendEmailConfirmationUser));
     }
     catch (Exception ex)
     {
         return(new ApiResponse <ResendEmailConfirmationUserVM>(StatusCodeType.Status500InternalServerError, "API threw an exception while resending Email Confirmation", null, null, ex));
     }
 }