Ejemplo n.º 1
0
 public void OnGet()
 {
     ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
     if (HttpContext.Session.GetInt32("cartId") != null)
     {
         productsInCart = (from p in ProductIndex.Products
                           join cp in _db.CartProducts on p.Id equals cp.ProductId
                           where cp.CartId == (int)HttpContext.Session.GetInt32("cartId")
                           select p).ToList();
     }
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnGet()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
            var user = await _userManager.GetUserAsync(User);

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

            return(Page());
        }
        public async Task <IActionResult> OnGetAsync(string returnUrl = null)
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
            // Ensure the user has gone through the username & password screen first
            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

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

            ReturnUrl = returnUrl;

            return(Page());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnGetAsync(string email, string returnUrl = null)
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

            if (email == null)
            {
                return(RedirectToPage("/Index"));
            }

            var user = await _userManager.FindByEmailAsync(email);

            if (user == null)
            {
                return(NotFound($"Unable to load user with email '{email}'."));
            }

            Email = email;
            // Once you add a real email sender, you should remove this code that lets you confirm the account
            DisplayConfirmAccountLink = false;
            if (DisplayConfirmAccountLink)
            {
                var userId = await _userManager.GetUserIdAsync(user);

                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                EmailConfirmationUrl = Url.Page(
                    "/Account/ConfirmEmail",
                    pageHandler: null,
                    values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl },
                    protocol: Request.Scheme);
            }

            return(Page());
        }
Ejemplo n.º 5
0
        public IActionResult OnGet(string code = null)
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

            if (code == null)
            {
                return(BadRequest("A code must be supplied for password reset."));
            }
            else
            {
                Input = new InputModel
                {
                    Code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code))
                };
                return(Page());
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> OnGet()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
            var user = await _userManager.GetUserAsync(User);

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

            if (!await _userManager.GetTwoFactorEnabledAsync(user))
            {
                throw new InvalidOperationException($"Cannot disable 2FA for user with ID '{_userManager.GetUserId(User)}' as it's not currently enabled.");
            }

            return(Page());
        }
Ejemplo n.º 7
0
        public async Task OnGetAsync(string returnUrl = null)
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

            if (!string.IsNullOrEmpty(ErrorMessage))
            {
                ModelState.AddModelError(string.Empty, ErrorMessage);
            }

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

            // Clear the existing external cookie to ensure a clean login process
            await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();

            ReturnUrl = returnUrl;
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> OnGetAsync()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID 'user.Id'."));
            }

            CurrentLogins = await _userManager.GetLoginsAsync(user);

            OtherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync())
                          .Where(auth => CurrentLogins.All(ul => auth.Name != ul.LoginProvider))
                          .ToList();
            ShowRemoveButton = user.PasswordHash != null || CurrentLogins.Count > 1;
            return(Page());
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> OnGetAsync()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
            var user = await _userManager.GetUserAsync(User);

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

            var hasPassword = await _userManager.HasPasswordAsync(user);

            if (hasPassword)
            {
                return(RedirectToPage("./ChangePassword"));
            }

            return(Page());
        }
Ejemplo n.º 10
0
        public IActionResult OnGet()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
            if (RecoveryCodes == null || RecoveryCodes.Length == 0)
            {
                return(RedirectToPage("./TwoFactorAuthentication"));
            }

            return(Page());
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> OnGet()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
            var user = await _userManager.GetUserAsync(User);

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

            HasAuthenticator = await _userManager.GetAuthenticatorKeyAsync(user) != null;

            Is2faEnabled = await _userManager.GetTwoFactorEnabledAsync(user);

            IsMachineRemembered = await _signInManager.IsTwoFactorClientRememberedAsync(user);

            RecoveryCodesLeft = await _userManager.CountRecoveryCodesAsync(user);

            return(Page());
        }
        public async Task <IActionResult> OnGetAsync()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
            var user = await _userManager.GetUserAsync(User);

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

            var isTwoFactorEnabled = await _userManager.GetTwoFactorEnabledAsync(user);

            if (!isTwoFactorEnabled)
            {
                var userId = await _userManager.GetUserIdAsync(user);

                throw new InvalidOperationException($"Cannot generate recovery codes for user with ID '{userId}' because they do not have 2FA enabled.");
            }

            return(Page());
        }
Ejemplo n.º 13
0
        // Add a product to the cart
        public IActionResult OnPost(int?categoryId, ProductVM product)
        {
            IsFiltering = categoryId != null ? true : false;

            if (product?.Id == null)
            {
                return(RedirectToPage("/Index"));
            }
            //need to validate against user or session
            int?cartId = HttpContext.Session.GetInt32("cartId");

            if (cartId == null) //new cart
            {
                Cart = new ShoppingCart(user == null ? null : user.Value);
                _db.Carts.Add(Cart);
                _db.SaveChanges();
                cartId = Cart.Id;
            }

            //update existing prod in existing cart
            CartProduct cp;

            //add new prod to existing cart

            cp = _db.CartProducts.Where(cp => cp.CartId == cartId && cp.ProductId == product.Id)
                 .FirstOrDefault();

            if (cp == null) //product not in this cart yet
            {
                cp = new CartProduct((int)cartId, product.Id, product.Price, product.Quantity);
                _db.CartProducts.Add(cp);
            }
            else //product is already in cart
            {
                //might want to validate for price change in the future;
                if ((cp.Quantity + product.Quantity) <= 50)  // Add quantity if won't exceed 50
                {
                    cp.AddQuantity(product.Quantity);
                }
                else // Display alert for exactly 50
                {
                    warningMsg = "You have reach the quantity limit for " + product.Name + "!";
                }
            }

            _db.SaveChanges();

            HttpContext.Session.SetInt32("cartId", (int)cartId);

            ProductIndex = _productVMService.GetProductsVM(HttpContext, categoryId);

            return(Page());
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> OnGetAsync(string userId, string email, string code)
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

            if (userId == null || email == null || code == null)
            {
                return(RedirectToPage("/Index"));
            }

            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{userId}'."));
            }

            code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
            var result = await _userManager.ChangeEmailAsync(user, email, code);

            if (!result.Succeeded)
            {
                StatusMessage = "Error changing email.";
                return(Page());
            }

            // In our UI email and user name are one and the same, so when we update the email
            // we need to update the user name.
            var setUserNameResult = await _userManager.SetUserNameAsync(user, email);

            if (!setUserNameResult.Succeeded)
            {
                StatusMessage = "Error changing user name.";
                return(Page());
            }

            await _signInManager.RefreshSignInAsync(user);

            StatusMessage = "Thank you for confirming your email change.";
            return(Page());
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> OnGetAsync(string userId, string code)
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

            if (userId == null || code == null)
            {
                return(RedirectToPage("/Index"));
            }

            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{userId}'."));
            }

            code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
            var result = await _userManager.ConfirmEmailAsync(user, code);

            StatusMessage = result.Succeeded ? "Thank you for confirming your email." : "Error confirming your email.";
            return(Page());
        }
Ejemplo n.º 16
0
 public void OnGet(int productId)
 {
     ProductDetail = _productVMService.GetProduct(productId);
     ProductIndex  = _productVMService.GetProductsVM(HttpContext, null);
 }
Ejemplo n.º 17
0
 public void OnGet()
 {
     ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
 }
Ejemplo n.º 18
0
        public IActionResult OnGetAsync()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

            return(RedirectToPage("./Login"));
        }
Ejemplo n.º 19
0
 public void OnGet()
 {
     ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
     RequestId    = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
 }
Ejemplo n.º 20
0
 public async Task OnGetAsync(string returnUrl = null)
 {
     ProductIndex   = _productVMService.GetProductsVM(HttpContext, null);
     ReturnUrl      = returnUrl;
     ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
 }