Ejemplo n.º 1
0
        protected void btnSubmit_click(object sender, EventArgs e)
        {
            if (IsUpdate)
            {
                //updating the record
                //get id out of session
                if (Session["ID"] != null)
                {
                    var id = Convert.ToInt32(Session["ID"]);
                    //get the Authentication object from the manager
                    var auth = AuthenticationManager.Find(id);
                    auth.FirstName = txtFirstname.Text;
                    auth.LastName  = txtLastname.Text;
                    auth.City      = txtCity.Text;
                    auth.Phone     = txtPhone.Text;
                    //pass auth to the manager for updating
                    AuthenticationManager.Update(auth);
                    //remove from auth ticket, clear session and redirect
                    FormsAuthentication.SignOut();
                    Session.Clear();
                    Response.Redirect("~/Registration");
                }
            }
            else
            {
                //inserting the record
                var customer = new Customer
                {
                    FirstName = txtFirstname.Text,
                    LastName  = txtLastname.Text,
                    City      = txtCity.Text,
                    Phone     = txtPhone.Text
                };
                //pass the auth object to the manager for inserting
                AuthenticationManager.Add(customer);
                Response.Redirect("~/Login");
            }
            var user = AuthenticationManager.Authenticate(txtFirstname.Text, txtLastname.Text);

            if (user == null)
            {
                //the customer is not authenticated
                txtFirstname.Text = string.Empty;
                txtLastname.Text  = string.Empty;
                txtFirstname.Focus();
                return;
            }
            //add id to session
            Session.Add("ID", ID);
            //redirect
            FormsAuthentication.RedirectFromLoginPage(user.FullName, false);
        }
        protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            if (IsUpdate)
            {
                //updating the record
                //get customer id out of session
                if (Session["CustomerID"] != null)
                {
                    var ID = Convert.ToInt32(Session["CustomerID"]);
                    //get the Authentication object from the manager
                    var auth = AuthenticationManager.Find(ID);
                    auth.Customer.FirstName = uxFirstName.Text;
                    auth.Customer.LastName  = uxLastName.Text;
                    auth.Customer.Phone     = uxPhone.Text;
                    auth.Customer.City      = uxCity.Text;
                    auth.Username           = uxUsername.Text;
                    auth.Password           = uxPassword.Text;
                    //pass auth to the manager for updating
                    AuthenticationManager.Update(auth);

                    //remove from auth ticket, clear session and redirect
                    FormsAuthentication.SignOut();
                    Session.Clear();
                    Response.Redirect("~/Login");
                }
            }
            else
            {
                //inserting the record
                var auth = new Authentication
                {
                    ID       = Convert.ToInt32(Session["CustomerID"]),
                    Username = uxUsername.Text,
                    Password = uxPassword.Text,
                    Customer = new Customer
                    {
                        FirstName = uxFirstName.Text,
                        LastName  = uxLastName.Text,
                        Phone     = uxPhone.Text,
                        City      = uxCity.Text
                    }
                };
                //pass the auth object to the manager for inserting
                AuthenticationManager.Add(auth);

                Response.Redirect("~/Login");
            }
        }
Ejemplo n.º 3
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            var customer = new Customer
            {
                FirstName = txtFName.Text,
                LastName  = txtLName.Text,
                Phone     = txtPhone.Text,
                City      = txtCity.Text
            };

            //pass the auth object to the manager for inserting
            AuthenticationManager.Add(customer);                                       // add customer to the database
            AuthenticationManager.Authenticate(customer.FirstName, customer.LastName); //authenticate the user
            Session.Add("customerID", customer.ID);                                    //add custer to session to use in leaseslip
            string custFullName = customer.FirstName + " " + customer.LastName;

            Session.Add("CustName", custFullName);
            // redirect - false means no persistent cookie


            FormsAuthentication.RedirectFromLoginPage(custFullName, false);
        }