Ejemplo n.º 1
0
        //*******************************************************
        //
        // The RegisterBtn_Click event handler is used on this page to
        // add a new user into the IBuySpy Customers database.
        //
        // The event handler then migrates any items stored in the user's
        // temporary (non-persistent) shopping cart to their
        // permanent customer account, adds a cookie to the client
        // (so that we can personalize the home page's welcome
        // message), and then redirects the browser back to the
        // originating page.
        //
        //*******************************************************

        private void RegisterBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            // Only attempt a login if all form fields on the page are valid
            if (Page.IsValid == true)
            {
                // Store off old temporary shopping cart ID
                IBuySpy.ShoppingCartDB shoppingCart = new IBuySpy.ShoppingCartDB();
                String tempCartId = shoppingCart.GetShoppingCartId();

                // Add New Customer to CustomerDB database
                IBuySpy.CustomersDB accountSystem = new IBuySpy.CustomersDB();
                String customerId = accountSystem.AddCustomer(Name.Text, Email.Text, Password.Text);

                if (customerId != "")
                {
                    // Set the user's authentication name to the customerId
                    FormsAuthentication.SetAuthCookie(customerId, false);

                    // Migrate any existing shopping cart items into the permanent shopping cart
                    shoppingCart.MigrateCart(tempCartId, customerId);

                    // Store the user's fullname in a cookie for personalization purposes
                    Response.Cookies["IBuySpy_FullName"].Value = Server.HtmlEncode(Name.Text);

                    // Redirect browser back to shopping cart page
                    Response.Redirect("ShoppingCart.aspx");
                }
                else
                {
                    MyError.Text = "Registration failed:&nbsp; That email address is already registered.<br><img align=left height=1 width=92 src=images/1x1.gif>";
                }
            }
        }
Ejemplo n.º 2
0
        //*******************************************************
        //
        // The LoginBtn_Click event is used on this page to
        // authenticate a customer's supplied username/password
        // credentials against a database.
        //
        // If the supplied username/password are valid, then
        // the event handler adds a cookie to the client
        // (so that we can personalize the home page's welcome
        // message), migrates any items stored in the user's
        // temporary (non-persistent) shopping cart to their
        // permanent customer account, and then redirects the browser
        // back to the originating page.
        //
        //*******************************************************

        private void LoginBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            // Only attempt a login if all form fields on the page are valid
            if (Page.IsValid == true)
            {
                // Save old ShoppingCartID
                IBuySpy.ShoppingCartDB shoppingCart = new IBuySpy.ShoppingCartDB();
                String tempCartID = shoppingCart.GetShoppingCartId();

                // Attempt to Validate User Credentials using CustomersDB
                IBuySpy.CustomersDB accountSystem = new IBuySpy.CustomersDB();
                String customerId = accountSystem.Login(email.Text, password.Text);

                if (customerId != null)
                {
                    // Migrate any existing shopping cart items into the permanent shopping cart
                    shoppingCart.MigrateCart(tempCartID, customerId);

                    // Lookup the customer's full account details
                    IBuySpy.CustomerDetails customerDetails = accountSystem.GetCustomerDetails(customerId);

                    // Store the user's fullname in a cookie for personalization purposes
                    Response.Cookies["IBuySpy_FullName"].Value = customerDetails.FullName;

                    // Make the cookie persistent only if the user selects "persistent" login checkbox
                    if (RememberLogin.Checked == true)
                    {
                        Response.Cookies["IBuySpy_FullName"].Expires = DateTime.Now.AddMonths(1);
                    }

                    // Redirect browser back to originating page
                    FormsAuthentication.RedirectFromLoginPage(customerId, RememberLogin.Checked);
                }
                else
                {
                    Message.Text = "Login Failed!";
                }
            }
        }