Exemple #1
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>();
            var user          = new ApplicationUser()
            {
                UserName = Email.Text, Email = Email.Text
            };
            IdentityResult result = manager.Create(user, Password.Text);

            if (result.Succeeded)
            {
                // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                //string code = manager.GenerateEmailConfirmationToken(user.Id);
                //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
                //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");

                signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);

                // Migrate the shopping cart, if necessary, after the user registers and logs in to the application during the checkout process
                using (var usersShoppingCart = new ShoppingCartActions()) {
                    string cartId = usersShoppingCart.GetCartId();
                    usersShoppingCart.MigrateCart(cartId, user.UserName);
                }

                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }
Exemple #2
0
        public IActionResult MigrateCart(string returnUrl = null)
        {
            var userID            = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var usersShoppingCart = new ShoppingCartActions(_httpContextAccessor, _context);

            usersShoppingCart.MigrateCart(userID);
            return(RedirectToLocal(returnUrl));
        }
Exemple #3
0
        public void MigrateShoppingCart(string Username)
        {
            ShoppingCartActions cart = new ShoppingCartActions();
            string _shoppingCartId   = cart.GetCartId();

            cart.MigrateCart(_shoppingCartId, Username);
            System.Web.HttpContext.Current.Session[ShoppingCartActions.cartSessionKey] = Username;
        }
Exemple #4
0
        protected void LogIn(object sender, EventArgs e)
        {
            if (IsValid)
            {
                // Validate the user password
                var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var signinManager = Context.GetOwinContext().GetUserManager <ApplicationSignInManager>();
                var user          = manager.FindByEmail(Email.Text);
                // This doen't count login failures towards account lockout
                // To enable password failures to trigger lockout, change to shouldLockout: true
                if (user != null)
                {
                    if (!user.EmailConfirmed)
                    {
                        FailureText.Text      = "Invalid login attempt, you must have a confirmed email account. Enter email and pass and click 'Resend Confirmation'";
                        ResendConfirm.Visible = true;
                        ErrorMessage.Visible  = true;
                    }

                    else
                    {
                        var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);

                        switch (result)
                        {
                        case SignInStatus.Success:
                            ShoppingCartActions usersShoppingCart = new ShoppingCartActions();
                            String cartId = usersShoppingCart.GetCartId();
                            usersShoppingCart.MigrateCart(cartId, Email.Text);
                            IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                            break;

                        case SignInStatus.LockedOut:
                            Response.Redirect("/Account/Lockout");
                            break;

                        case SignInStatus.RequiresVerification:
                            Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
                                                            Request.QueryString["ReturnUrl"],
                                                            RememberMe.Checked),
                                              true);
                            break;

                        case SignInStatus.Failure:
                        default:
                            FailureText.Text     = "Invalid login attempt";
                            ErrorMessage.Visible = true;
                            break;
                        }
                    }
                }
            }
        }
Exemple #5
0
        protected void LogIn(object sender, EventArgs e)
        {
            if (IsValid)
            {
                // Validate the user password
                var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var signinManager = Context.GetOwinContext().GetUserManager <ApplicationSignInManager>();

                // This doen't count login failures towards account lockout
                // To enable password failures to trigger lockout, change to shouldLockout: true
                var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);

                switch (result)
                {
                case SignInStatus.Success:
                    // Migrate a cart the user may have created before logging into the application to checkout
                    using (var usersShoppingCart = new ShoppingCartActions()) {
                        string cartId = usersShoppingCart.GetCartId();
                        usersShoppingCart.MigrateCart(cartId, User.Identity.Name);
                    }

                    IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                    break;

                case SignInStatus.LockedOut:
                    Response.Redirect("/Account/Lockout");
                    break;

                case SignInStatus.RequiresVerification:
                    Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
                                                    Request.QueryString["ReturnUrl"],
                                                    RememberMe.Checked),
                                      true);
                    break;

                case SignInStatus.Failure:
                default:
                    FailureText.Text     = "Invalid login attempt";
                    ErrorMessage.Visible = true;
                    break;
                }
            }
        }