public async Task <IActionResult> Login2Factor(bool RememberMe, string returnUrl) { var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); if (user == null) { _notification.AddToastNotification("Could not load 2-Factor Authentication for you", NotificationHelper.NotificationType.error, new ToastNotificationOption { NewestOnTop = true, CloseButton = true, PositionClass = "toast-top-right", PreventDuplicates = true }); return(View()); } var model = new Login2FAViewModel { RememberMe = RememberMe }; ViewData["returnUrl"] = returnUrl; return(View(model)); }
public async Task <IActionResult> Login2Factor(Login2FAViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); if (user == null) { _notification.AddToastNotification("No Such User Exists!", NotificationHelper.NotificationType.error, new ToastNotificationOption { NewestOnTop = true, CloseButton = true, PositionClass = "toast-top-right", PreventDuplicates = true }); return(View(model)); } var authcode = model.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty); var result = await _signInManager.TwoFactorAuthenticatorSignInAsync(authcode, model.RememberMe, model.RememberMachine); if (result.Succeeded) { return(RedirectToLocal(returnUrl)); } if (result.IsLockedOut) { return(RedirectToAction(nameof(LockedOut))); } if (result.IsNotAllowed) { return(RedirectToAction(nameof(AccessDenied))); } } _notification.AddToastNotification("You have Made Errors", NotificationHelper.NotificationType.error, new ToastNotificationOption { NewestOnTop = true, CloseButton = true, PositionClass = "toast-top-right", PreventDuplicates = true }); return(View(model)); }