Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync(int?categoryId, string captcha, string returnUrl = null)
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

            if (!await _captchaValidator.IsCaptchaPassedAsync(captcha))
            {
                ModelState.AddModelError("captcha", "Captcha validation failed");
                return(Page());
            }

            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");

                    var user = await _userManager.FindByEmailAsync(Input.Email);

                    if (user != null)
                    {
                        await _loginCartManagerService.ManageCart(HttpContext, user.Id);
                    }

                    return(LocalRedirect(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync(bool rememberMe, string returnUrl = null)
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            returnUrl = returnUrl ?? Url.Content("~/");

            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

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

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

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

            if (result.Succeeded)
            {
                _logger.LogInformation("User with ID '{UserId}' logged in with 2fa.", user.Id);

                if (user != null)
                {
                    await _loginCartManagerService.ManageCart(HttpContext, user.Id);
                }

                return(LocalRedirect(returnUrl));
            }
            else if (result.IsLockedOut)
            {
                _logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id);
                return(RedirectToPage("./Lockout"));
            }
            else
            {
                _logger.LogWarning("Invalid authenticator code entered for user with ID '{UserId}'.", user.Id);
                ModelState.AddModelError(string.Empty, "Invalid authenticator code.");
                return(Page());
            }
        }
Esempio n. 3
0
        public async Task OnGetAsync(int?categoryId)
        {
            CategoryID  = categoryId;
            IsFiltering = categoryId != null ? true : false;

            int?cartId = HttpContext.Session.GetInt32("cartId");

            //If logged in and without a cart session, check if there is a recent unclosed cart session
            if (user != null && cartId == null)
            {
                await _loginCartManagerService.ManageCart(HttpContext, user.Value);
            }

            ProductIndex = _productVMService.GetProductsVMFilteredSorted(HttpContext, CategoryID, SearchString, Sort);
            if (!String.IsNullOrEmpty(SearchString) || !String.IsNullOrEmpty(Sort))
            {
                IsFiltering = true;
            }
        }