Example #1
0
        protected void DBPasswordValidator_ServerValidate(object source, ServerValidateEventArgs args)
        {
            Customers isPasswordCorrect = CustomersDB.GetCustomerbyPassword(HashPassword.ApplyHash(txtOldCustPassword.Text));

            if (isPasswordCorrect == null)
            {
                args.IsValid = false;
                Control loginFail = FindControl("LoginFailure");
                loginFail.Visible = true;
                string script = @"document.getElementById('" + LoginFailure.ClientID + "').innerHTML='Unable to update password.' ;setTimeout(function(){document.getElementById('" + LoginFailure.ClientID + "').style.display='none';},5000);";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "somekey", script, true);
            }
            else
            {
                args.IsValid = true;
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string hashedPswd = HashPassword.ApplyHash(txtCustPassword.Text);

                if (txtCustEmail.Text != "")
                {
                    Customers cust = new Customers(txtCustFirstName.Text, txtCustLastName.Text, txtCustAddress.Text, txtCustCity.Text, ddlCustProv.Text, txtCustPostal.Text, txtCustCountry.Text, FormatePhoneNo.ApplyFormatting(txtCustHomePhone.Text), FormatePhoneNo.ApplyFormatting(txtCustBusPhone.Text), txtCustEmail.Text, hashedPswd, "No");
                    try
                    {
                        int insertCustId = CustomersDB.AddCustomer(cust);
                        SendActivationEmail(txtCustEmail.Text);
                        Response.Redirect("ConfirmationPage.aspx");
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    string defaultEmail = "defaultemail" + CustomersDB.AssignEmailNo() + "@travelexperts.com";
                    Application["defaultEmail"] = defaultEmail;

                    Customers cust = new Customers(txtCustFirstName.Text, txtCustLastName.Text, txtCustAddress.Text, txtCustCity.Text, ddlCustProv.Text, txtCustPostal.Text, txtCustCountry.Text, FormatePhoneNo.ApplyFormatting(txtCustHomePhone.Text), FormatePhoneNo.ApplyFormatting(txtCustBusPhone.Text), defaultEmail, hashedPswd, "Yes");
                    try
                    {
                        int insertCustId = CustomersDB.AddCustomer(cust);
                        Response.Redirect("ConfirmationPageNoEmail.aspx");
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
Example #3
0
 protected void btnUpdtPswd_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         Customers loggedCustomer      = new Customers(Session["custEmail"].ToString(), HashPassword.ApplyHash(txtOldCustPassword.Text));
         Customers updatedPswdCustomer = new Customers(Session["custEmail"].ToString(), HashPassword.ApplyHash(txtNewCustPassword.Text));
         try
         {
             bool updatePswdSuccessful = CustomersDB.UpdateCustomerPassword(loggedCustomer, updatedPswdCustomer);
             if (updatePswdSuccessful)
             {
                 Control loginSuccess = FindControl("LoginSuccess");
                 loginSuccess.Visible = true;
                 string script = @"document.getElementById('" + LoginSuccess.ClientID + "').innerHTML='Password update successful.' ;setTimeout(function(){document.getElementById('" + LoginSuccess.ClientID + "').style.display='none';},5000);";
                 //Page.ClientScript.RegisterStartupScript(this.GetType(), "somekey", script, true);
                 ScriptManager.RegisterStartupScript(this, this.GetType(), "Show status", script, true);
             }
             else
             {
                 Control loginFail = FindControl("LoginFailure");
                 loginFail.Visible = true;
                 string script = @"document.getElementById('" + LoginFailure.ClientID + "').innerHTML='Unable to update password.' ;setTimeout(function(){document.getElementById('" + LoginFailure.ClientID + "').style.display='none';},5000);";
                 //Page.ClientScript.RegisterStartupScript(this.GetType(), "somekey", script, true);
                 ScriptManager.RegisterStartupScript(this, this.GetType(), "Show status", script, true);
             }
         }
         catch (Exception)
         {
             ExceptionScript();
         }
     }
 }