예제 #1
0
        public async Task<IActionResult> OnPostAsync(string returnUrl = null)
        {
            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.");
                    return LocalRedirect(returnUrl);
                }
                if (result.RequiresTwoFactor)
                {
                    return RedirectToPage("./LoginWith2fa", (ReturnUrl: returnUrl, Input.RememberMe));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return RedirectToPage("./Lockout");
                }
                ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                return Page();
            }

            // If we got this far, something failed, redisplay form
            return Page();
        }
예제 #2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new BingolUser {
                    UserFirstName = Input.FirstName, UserLastName = Input.LastName,
                    UserName      = Input.Email, Email = Input.Email, PhoneNumber = Input.PhoneNumber, UserCity = Input.City,
                    UserState     = Input.State, UserZip = Input.ZipCode, UserCountry = Input.Country, UserAddress = Input.BillingAddress,
                    UserAddress2  = Input.ShippingAddress, UserRegistrationDate = DateTime.Now,
                    UserIp        = new WebClient().DownloadString(IchanZip).TrimEnd(), EmailConfirmed = true,
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");
                    await _userManager.AddToRoleAsync(user, "Customer");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: (area: "Identity", userId: user.Id, code, 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", (email: Input.Email, 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());
        }
예제 #3
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            await LoadAsync(returnUrl);

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

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

            if (user == null)
            {
                return(Page());
            }

            // 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(user, Input.Password, Input.RememberMe, lockoutOnFailure : false);

            if (result.Succeeded)
            {
                _logger.LogInformation("User logged in.");
                return(LocalRedirect(ReturnUrl));
            }
            if (result.RequiresTwoFactor)
            {
                return(RedirectToPage("./LoginWith2fa", (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());
            }
        }
예제 #4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                var result = await _signInManager.PasswordSignInAsync(
                    Input.Email, Input.Password, Input.RememberMe, false);

                _logger.LogInformation(result.ToString());

                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");
                    return(Redirect(returnUrl));
                }

                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa",
                                          (ReturnUrl: returnUrl, Input.RememberMe)));
                }

                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }

                ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                return(Page());
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
예제 #5
0
 public RedirectWithErrorMessage(RedirectToPage redirectToPage, ErrorMessageCode errorMessageCode)
 {
     this.ErrorMessageCode = errorMessageCode;
     this.RedirectToPage   = redirectToPage;
 }