Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CustomerId"] == null)//check login
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                if (!IsPostBack)//load the customer information
                {
                    int             CustomerId = (int)Session["CustomerId"];
                    CustomerAccount ca         = new CustomerAccount();
                    ca = CustomerAccountDB.GetAccountByID(CustomerId);

                    txtUsername.Text          = ca.CustUserName;
                    txtFirstName.Text         = ca.CustFirstName;
                    txtLastName.Text          = ca.CustLastName;
                    txtAddress.Text           = ca.CustAddress;
                    txtCity.Text              = ca.CustCity;
                    ddlProvince.SelectedValue = ca.CustProv;
                    txtPostal.Text            = ca.CustPostal;
                    txtCountry.Text           = ca.CustCountry;
                    txtHomePhone.Text         = ca.CustHomePhone;
                    txtBusPhone.Text          = ca.CustBusPhone;
                    txtEmail.Text             = ca.CustEmail;
                }
            }
        }
Exemple #2
0
        protected void UpdateUser(object sender, EventArgs e)
        {
            if ((txtConfirmPassword.Text.Length == 0 && txtPassword.Text.Length != 0))//check password matching
            {
                lblComfirmPasswordError.ForeColor = System.Drawing.Color.Red;
                lblComfirmPasswordError.Text      = "Passwords do not match";
                txtPassword.Focus();
            }
            else
            {
                lblComfirmPasswordError.Text = "";
                int             userId = 0;
                CustomerAccount ca     = new CustomerAccount();
                ca.CustomerId    = (int)Session["CustomerId"];
                ca.CustFirstName = txtFirstName.Text.Trim();
                ca.CustLastName  = txtLastName.Text.Trim();
                ca.CustAddress   = txtAddress.Text.Trim();
                ca.CustCity      = txtCity.Text.Trim();
                ca.CustProv      = ddlProvince.SelectedValue;
                ca.CustPostal    = txtPostal.Text.Trim();
                ca.CustCountry   = txtCountry.Text.Trim();
                ca.CustHomePhone = txtHomePhone.Text.Trim();
                ca.CustBusPhone  = txtBusPhone.Text.Trim();
                ca.CustEmail     = txtEmail.Text.Trim();
                ca.CustUserName  = txtUsername.Text.Trim();
                if (txtPassword.Text.Length != 0)
                {
                    string hashedPassword = Crypto.HashPassword(txtPassword.Text.Trim());
                    ca.CustPassword = hashedPassword;//get hashed Password value
                }
                else
                {
                    string hashedPassword = Crypto.HashPassword(Session["CustPassword"].ToString());
                    ca.CustPassword = hashedPassword;
                }

                userId = CustomerAccountDB.UpdateAccount(ca);//save the updates into database

                string message = string.Empty;
                if (userId != 0)
                {
                    message = "Information update successfully";
                    ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
                }
                else
                {
                    message = "Error occured while updating.";
                    ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
                }
            }
        }
        protected void RegisterUser(object sender, EventArgs e)
        {
            int             userId = 0;//variable for hold userId
            CustomerAccount ca     = new CustomerAccount();

            ca.CustFirstName = txtFirstName.Text.Trim();  //get firstname value from form
            ca.CustLastName  = txtLastName.Text.Trim();   //get LastName value from form
            ca.CustAddress   = txtAddress.Text.Trim();    //get Address value from form
            ca.CustCity      = txtCity.Text.Trim();       //get City value from form
            ca.CustProv      = ddlProvince.SelectedValue; //get Province value from form
            ca.CustPostal    = txtPostal.Text.Trim();     //get Postal value from form
            ca.CustCountry   = txtCountry.Text.Trim();    //get Country value from form
            ca.CustHomePhone = txtHomePhone.Text.Trim();  //get HomePhone value from form
            ca.CustBusPhone  = txtBusPhone.Text.Trim();   //get BusPhone value from form
            ca.CustEmail     = txtEmail.Text.Trim();      //get Email value from form
            ca.CustUserName  = txtUsername.Text.Trim();   //get Username value from form

            string hashedPassword = Crypto.HashPassword(txtPassword.Text.Trim());

            ca.CustPassword = hashedPassword;//get Password value from form


            userId = CustomerAccountDB.InsertNewAccount(ca);

            string message = string.Empty;

            if (userId == -1)//checks if the user  id is wrong
            {
                message = "Username already exists.\\nPlease choose a different username.";
                ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
            }
            else
            {
                Session["CustomerId"]    = userId;                                 //save  userid
                Session["CustFirstName"] = ca.CustFirstName;                       //save customer name
                Session["CustPassword"]  = ca.CustPassword;                        //save customer password
                message = "Registration successful.\\nRedirecting to Home page.."; //display message
                Response.Write("<script language='javascript'>alert('" + message + "');</script>");
                Server.Transfer("Home.aspx", true);
            }
        }
Exemple #4
0
        //verify the input username and password(with the hashedpassword)
        protected void Submit_Click(object sender, EventArgs e)
        {
            var verify = false;

            CustomerAccount Cust = new CustomerAccount();

            Cust.CustUserName = txtUserName.Text;
            Cust = CustomerAccountDB.UserChecker(Cust);

            if (Cust.CustomerId != 0)
            {
                verify = Crypto.VerifyHashedPassword(Cust.CustPassword, txtPassword.Text);
                if (verify == true)
                {
                    Session["CustomerId"]    = Cust.CustomerId;
                    Session["CustFirstName"] = Cust.CustFirstName;
                    Session["CustPassword"]  = txtPassword.Text;
                    if (Session["prevUrl"] != null)
                    {
                        Response.Redirect(Session["prevUrl"].ToString());
                    }
                    else
                    {
                        Response.Redirect("Home.aspx");
                    }
                }
                else
                {
                    lblMessage.Text      = "Username or Password is incorrect";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                }
            }
            else
            {
                lblMessage.Text      = "Username or Password is incorrect";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }