public async Task <IActionResult> LoginWithMfa(bool rememberMe, string returnUrl = "/AccountManage") { var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); if (user == null) { throw new InvalidOperationException("Unable to load two-factor authentication."); } var loginWithMfaViewModel = new LoginWithMfaViewModel() { RememberMe = rememberMe, ReturnUrl = returnUrl }; return(View(loginWithMfaViewModel)); }
public async Task <IActionResult> LoginWithMfa(LoginWithMfaViewModel loginWithMfaViewModel) { if (ModelState.IsValid) { var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); if (user == null) { throw new InvalidOperationException("Invalid operation."); } var authenticationCode = loginWithMfaViewModel.AuthenticationCode.Replace(" ", string.Empty).Replace("-", string.Empty); var result = await _signInManager.TwoFactorAuthenticatorSignInAsync(authenticationCode, loginWithMfaViewModel.RememberMe, loginWithMfaViewModel.RememberComputer); if (result.Succeeded) { return(Redirect(loginWithMfaViewModel.ReturnUrl)); } } ModelState.AddModelError(string.Empty, "invalid information"); return(View(loginWithMfaViewModel)); }