public async Task <IActionResult> SendCode(SendCodeViewModel model) { if (!ModelState.IsValid) { return(View()); } var user = await SignInManager.GetTwoFactorAuthenticationUserAsync(); if (user == null) { return(ErrorResult()); } // Generate the token and send it var code = await UserManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider); if (string.IsNullOrWhiteSpace(code)) { return(ErrorResult()); } if (model.SelectedProvider == "Email") { await EmailSender.SendEmailCommunicationAsync( SystemCommunicationPurposes.UserTwoFactorLoginCode, CommunicationModelFactory.CreateSimpleCodeModel(code), await UserManager.GetEmailAsync(user)); } else if (model.SelectedProvider == "Phone") { await SmsSender.SendSmsCommunicationAsync( SystemCommunicationPurposes.UserTwoFactorLoginCode, CommunicationModelFactory.CreateSimpleCodeModel(code), await UserManager.GetPhoneNumberAsync(user)); } return(RedirectToAction(nameof(VerifyCode), new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe })); }