Пример #1
0
        protected void SignIn(object sender, EventArgs e)
        {
            var userStore   = new UserStore <IdentityUser>();
            var userManager = new UserManager <IdentityUser>(userStore);
            var user        = userManager.Find(UserName.Text, Password.Text);

            if (user != null)
            {
                var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                var userIdentity          = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);

                authenticationManager.SignIn(new AuthenticationProperties()
                {
                    IsPersistent = false
                }, userIdentity);

                ProjektRWA.Logic.ShoppingCartActions usersShoppingCart = new ProjektRWA.Logic.ShoppingCartActions();
                String cartId = usersShoppingCart.GetCartId();
                usersShoppingCart.MigrateCart(cartId, UserName.Text);

                Response.Redirect("~/Naslovna.aspx");
            }
            else
            {
                StatusText.Text     = "Invalid username or password.";
                LoginStatus.Visible = true;
            }
        }
Пример #2
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            // Default UserStore constructor uses the default connection string named: DefaultConnection
            var userStore = new UserStore <IdentityUser>();
            var manager   = new UserManager <IdentityUser>(userStore);
            var user      = new IdentityUser()
            {
                UserName = UserName.Text
            };

            IdentityResult result = manager.Create(user, Password.Text);

            if (result.Succeeded)
            {
                var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                var userIdentity          = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
                authenticationManager.SignIn(new AuthenticationProperties()
                {
                }, userIdentity);

                using (ProjektRWA.Logic.ShoppingCartActions usersShoppingCart = new ProjektRWA.Logic.ShoppingCartActions())
                {
                    String cartId = usersShoppingCart.GetCartId();
                    usersShoppingCart.MigrateCart(cartId, user.Id);
                }
                Response.Redirect("~/Naslovna.aspx");
            }
            else
            {
                StatusMessage.Text = result.Errors.FirstOrDefault();
            }
        }