public async Task <IActionResult> LoginWith2fa(LoginWith2faVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var korisnik = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (korisnik == null)
            {
                throw new InvalidOperationException($"Greška pri 2FA.");
            }

            var authenticatorCode = model.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty);

            var result = await _signInManager.TwoFactorAuthenticatorSignInAsync(authenticatorCode, model.RememberMe, model.RememberMachine);

            if (result.Succeeded)
            {
                _applicationUserService.SetLogedInTimeStamp(_applicationUserService.GetUser(korisnik.UserName));
                return(RedirectToAction("Index", "Home"));
            }
            else if (result.IsLockedOut)
            {
                //Korisnik locked out
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                model.StatusMessage = "Pogrešan kod unesen.";
                return(View(model));
            }
        }
示例#2
0
        public async Task <IActionResult> LoginWith2fa(LoginWith2faVM model, bool rememberMe, string returnUrl = null)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var authenticatorCode = model.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty);

            var result = await _signInManager.TwoFactorAuthenticatorSignInAsync(authenticatorCode, rememberMe, model.RememberMachine);

            if (result.Succeeded)
            {
                _logger.LogInformation("User with ID {UserId} logged in with 2fa.", user.Id);
                return(RedirectToLocal(returnUrl));
            }
            else if (result.IsLockedOut)
            {
                _logger.LogWarning("User with ID {UserId} account locked out.", user.Id);
                return(RedirectToAction(nameof(Lockout)));
            }
            else
            {
                _logger.LogWarning("Invalid authenticator code entered for user with ID {UserId}.", user.Id);
                ModelState.AddModelError(string.Empty, "Invalid authenticator code.");
                return(View());
            }
        }
        public IActionResult LoginWith2fa(bool rememberMe)
        {
            var model = new LoginWith2faVM
            {
                RememberMe = rememberMe
            };

            return(View(model));
        }
示例#4
0
        public async Task <IActionResult> LoginWith2fa(bool rememberMe, string returnUrl = null)
        {
            // Ensure the user has gone through the username & password screen first
            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                throw new ApplicationException($"Unable to load two-factor authentication user.");
            }

            var model = new LoginWith2faVM {
                RememberMe = rememberMe
            };

            ViewData["ReturnUrl"] = returnUrl;

            return(View(model));
        }