Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(Input.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(RedirectToPage("./ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please
                // visit https://go.microsoft.com/fwlink/?LinkID=532713
                var code = await _userManager.GeneratePasswordResetTokenAsync(user);

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

                await _emailSender.SendEmailAsync(
                    Input.Email,
                    "Reset Password",
                    $"Please reset your password by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                return(RedirectToPage("./ForgotPasswordConfirmation"));
            }

            return(Page());
        }
Ejemplo n.º 2
0
        public ActionResult Index(String en, String an, Double?sp, Boolean?s, Double?ep, long Id = 0, int PageSize = PAGE_SIZE, int page = 1, Sorts sb = Sorts.IdUp)
        {
            //page = page > 1 ? page : 1;
            //PageSize = PageSize > 0 ? PageSize : PAGE_SIZE;
            List <ProductIndexManagerDTO> productDTOs = _productManagerService.FilterProducts(an, en, sp, ep, s, Id, sb, CurrentLanguage, CurrentCurrency, CurrentWebsite);

            Mapper.Initialize(c => c.CreateMap <ProductIndexManagerDTO, ProductIndexManagerVM>());
            List <ProductIndexManagerVM> products = Mapper.Map <List <ProductIndexManagerDTO>, List <ProductIndexManagerVM> >(productDTOs);
            ProductIndexVM productIndexVM         = new ProductIndexVM
            {
                Products       = products.ToPagedList(page, PageSize),
                SizeCategories = _productManagerService.GetSizeCategories(CurrentLanguage),
                filters        = new ProductManagerFiltersVM
                {
                    ArabicName  = an,
                    EnglishName = en,
                    StartPrice  = sp,
                    EndPrice    = ep,
                    PageNum     = page,
                    PageSize    = PageSize,
                    Status      = s,
                    SortBy      = sb
                }
            };

            return(View(productIndexVM));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            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)}'."));
            }

            _logger.LogInformation("User with ID '{UserId}' asked for their personal data.", _userManager.GetUserId(User));

            // Only include personal data for download
            var personalData      = new Dictionary <string, string>();
            var personalDataProps = typeof(IdentityUser).GetProperties().Where(
                prop => Attribute.IsDefined(prop, typeof(PersonalDataAttribute)));

            foreach (var p in personalDataProps)
            {
                personalData.Add(p.Name, p.GetValue(user)?.ToString() ?? "null");
            }

            var logins = await _userManager.GetLoginsAsync(user);

            foreach (var l in logins)
            {
                personalData.Add($"{l.LoginProvider} external login provider key", l.ProviderKey);
            }

            Response.Headers.Add("Content-Disposition", "attachment; filename=PersonalData.json");
            return(new FileContentResult(JsonSerializer.SerializeToUtf8Bytes(personalData), "application/json"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            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);

            var userId = await _userManager.GetUserIdAsync(user);

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

            var recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10);

            RecoveryCodes = recoveryCodes.ToArray();

            _logger.LogInformation("User with ID '{UserId}' has generated new 2FA recovery codes.", userId);
            StatusMessage = "You have generated new recovery codes.";
            return(RedirectToPage("./ShowRecoveryCodes"));
        }
Ejemplo n.º 5
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.º 6
0
        public async Task <IActionResult> OnPostAsync()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            if (user == null)
            {
                // Don't reveal that the user does not exist
                return(RedirectToPage("./ResetPasswordConfirmation"));
            }

            var result = await _userManager.ResetPasswordAsync(user, Input.Code, Input.Password);

            if (result.Succeeded)
            {
                return(RedirectToPage("./ResetPasswordConfirmation"));
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }
            return(Page());
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> OnGetLinkLoginCallbackAsync()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

            var user = await _userManager.GetUserAsync(User);

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

            var info = await _signInManager.GetExternalLoginInfoAsync(user.Id);

            if (info == null)
            {
                throw new InvalidOperationException($"Unexpected error occurred loading external login info for user with ID '{user.Id}'.");
            }

            var result = await _userManager.AddLoginAsync(user, info);

            if (!result.Succeeded)
            {
                StatusMessage = "The external login was not added. External logins can only be associated with one account.";
                return(RedirectToPage());
            }

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

            StatusMessage = "The external login was added.";
            return(RedirectToPage());
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> OnPostAsync()
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(User);

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

            var addPasswordResult = await _userManager.AddPasswordAsync(user, Input.NewPassword);

            if (!addPasswordResult.Succeeded)
            {
                foreach (var error in addPasswordResult.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
                return(Page());
            }

            await _signInManager.RefreshSignInAsync(user);

            StatusMessage = "Your password has been set.";

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

            return(Page());
        }
Ejemplo n.º 10
0
        public IActionResult OnPost(string provider, string returnUrl = null)
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

            // Request a redirect to the external login provider.
            var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl });
            var properties  = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            return(new ChallengeResult(provider, properties));
        }
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)}'."));
            }

            return(Page());
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> OnPostAsync()
        {
            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 (!ModelState.IsValid)
            {
                await LoadSharedKeyAndQrCodeUriAsync(user);

                return(Page());
            }

            // Strip spaces and hypens
            var verificationCode = Input.Code.Replace(" ", string.Empty).Replace("-", string.Empty);

            var is2faTokenValid = await _userManager.VerifyTwoFactorTokenAsync(
                user, _userManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode);

            if (!is2faTokenValid)
            {
                ModelState.AddModelError("Input.Code", "Verification code is invalid.");
                await LoadSharedKeyAndQrCodeUriAsync(user);

                return(Page());
            }

            await _userManager.SetTwoFactorEnabledAsync(user, true);

            var userId = await _userManager.GetUserIdAsync(user);

            _logger.LogInformation("User with ID '{UserId}' has enabled 2FA with an authenticator app.", userId);

            StatusMessage = "Your authenticator app has been verified.";

            if (await _userManager.CountRecoveryCodesAsync(user) == 0)
            {
                var recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10);

                RecoveryCodes = recoveryCodes.ToArray();
                return(RedirectToPage("./ShowRecoveryCodes"));
            }
            else
            {
                return(RedirectToPage("./TwoFactorAuthentication"));
            }
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> OnPostLinkLoginAsync(string provider)
        {
            ProductIndex = _productVMService.GetProductsVM(HttpContext, null);

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

            // Request a redirect to the external login provider to link a login for the current user
            var redirectUrl = Url.Page("./ExternalLogins", pageHandler: "LinkLoginCallback");
            var properties  = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, _userManager.GetUserId(User));

            return(new ChallengeResult(provider, properties));
        }
Ejemplo n.º 14
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());
        }
        public virtual ActionResult Index()
        {
            var pageOfProductsDto = this.productService.GetProducts(
                p => p.Price > 1000,
                2,
                2,
                new SortExpression <Product>(p => p.Name, ListSortDirection.Ascending),
                new SortExpression <Product>(p => p.Description, ListSortDirection.Descending));

            var vm = new ProductIndexVM {
                Products = pageOfProductsDto.Products.ToList(), Page = 2, TotalCount = pageOfProductsDto.TotalCount
            };

            return(View(Views.ViewNames.Index, vm));
        }
        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.º 17
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            ProductIndex   = _productVMService.GetProductsVM(HttpContext, null);
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

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

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> OnPost()
        {
            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)}'."));
            }

            await _signInManager.ForgetTwoFactorClientAsync();

            StatusMessage = "The current browser has been forgotten. When you login again from this browser you will be prompted for your 2fa code.";
            return(RedirectToPage());
        }
Ejemplo n.º 19
0
        public ProductIndexVM GetProductsVM(HttpContext context, int?categoryId)
        {
            List <Product>  products   = _productRepo.GetAll().ToList();
            List <Category> categories = _categoryRepo.GetAll().ToList();

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

            int total = 0;

            if (cartId != null)
            {
                foreach (var p in products)
                {
                    total += (from cp in _db.CartProducts where cp.ProductId == p.Id && cp.CartId == cartId select cp.Quantity).FirstOrDefault();
                }
            }

            if (categoryId != null)
            {
                products = (from p in products
                            join pc in _db.ProductCategories on p.Id equals pc.ProductId
                            join c in categories on pc.CategoryId equals c.Id
                            where c.Id == categoryId
                            select p).ToList();
            }

            var vm = new ProductIndexVM()
            {
                Products = products.Select(p => new ProductVM
                {
                    Id          = p.Id,
                    Name        = p.Name,
                    Price       = p.Price,
                    ImageUri    = p.ImageUri,
                    Description = p.Description,
                    Quantity    = cartId != null ? (from cp in _db.CartProducts where cp.ProductId == p.Id && cp.CartId == cartId select cp.Quantity).FirstOrDefault() : 0
                }).ToList(),
                Categories = categories.Select(c => new CategoryVM
                {
                    Id   = c.Id,
                    Name = c.Name
                }).ToList(),
                TotalQuantity = total
            };

            return(vm);
        }
Ejemplo n.º 20
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.º 21
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.º 22
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.º 23
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.º 24
0
        public IActionResult Search(string search = null, int?page = 1)
        {
            int skipCount = ((int)page - 1) * 9;
            var product   = _context.Products.OrderBy(p => p.Id).Skip(skipCount).Take(9).ToList();// belke 2 dene product var ona gore reaksiya vermir birini silek>?

            if (search != null)
            {
                product = _context.Products.Where(p => p.Name.Contains(search)).OrderBy(p => p.Id).Skip(skipCount).Take(9).ToList();
            }
            ViewData["allProductCount"] = _context.Products.ToList().Count;
            ViewData["activePage"]      = page;
            ProductIndexVM productIndexVM = new ProductIndexVM()
            {
                products = product
            };

            return(RedirectToAction(nameof(Index), new { search = search, page = 1 }));
        }
Ejemplo n.º 25
0
        public IActionResult Index(string search = null, int?page = 1)
        {
            int skipCount = ((int)page - 1) * 9;
            var product   = _context.Products.OrderBy(p => p.Id).Skip(skipCount).Take(9).ToList();

            if (search != null)
            {
                product = _context.Products.Where(p => p.Name.Contains(search)).OrderBy(p => p.Id).Skip(skipCount).Take(9).ToList();
            }
            ViewData["allProductCount"] = _context.Products.ToList().Count;
            ViewData["activePage"]      = page;
            ProductIndexVM productIndexVM = new ProductIndexVM()
            {
                products = product
            };

            return(View(productIndexVM));
        }
Ejemplo n.º 26
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());
            }
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> OnPostChangeEmailAsync()
        {
            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 (!ModelState.IsValid)
            {
                await LoadAsync(user);

                return(Page());
            }

            var email = await _userManager.GetEmailAsync(user);

            if (Input.NewEmail != email)
            {
                var userId = await _userManager.GetUserIdAsync(user);

                var code = await _userManager.GenerateChangeEmailTokenAsync(user, Input.NewEmail);

                var callbackUrl = Url.Page(
                    "/Account/ConfirmEmailChange",
                    pageHandler: null,
                    values: new { userId = userId, email = Input.NewEmail, code = code },
                    protocol: Request.Scheme);
                await _emailSender.SendEmailAsync(
                    Input.NewEmail,
                    "Confirm your email",
                    $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                StatusMessage = "Confirmation link to change email sent. Please check your email.";
                return(RedirectToPage());
            }

            StatusMessage = "Your email is unchanged.";
            return(RedirectToPage());
        }
Ejemplo n.º 28
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.º 29
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());
        }