Esempio n. 1
0
        public bool CheckCurrentUserBeforePurchase()
        {
            BoxtyUser boxtyUser = this.GetCurrentUser();

            if (boxtyUser.FirstName == null || boxtyUser.LastName == null ||
                boxtyUser.PhoneNumber == null || boxtyUser.Address == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new BoxtyUser {
                    UserName = Input.UserName, Email = Input.UserName
                };
                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 },
                        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>.");

                    await this._userManager.AddToRoleAsync(user, GlobalConstants.DefaultRole);

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
                    }
                    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());
        }
Esempio n. 3
0
        public async Task SeedAsync(BoxtyDbContext dbContext, IServiceProvider serviceProvider)
        {
            var userManager = serviceProvider.GetRequiredService <UserManager <BoxtyUser> >();

            var user = await userManager.FindByNameAsync("admin");

            if (user != null)
            {
                return;
            }

            user =
                new BoxtyUser
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
            };
            await userManager.CreateAsync(user, "123456");

            await userManager.AddToRoleAsync(user, GlobalConstants.Admin);
        }