protected void LoginButton(object sender, EventArgs e) { if (Page.IsValid) { string hashedPswd = HashPassword.ApplyHash(txtModalCustPassword.Text); //string custEmail = String.Format("{0}", Request.Form["email_modal"]); //string custPassword = String.Format("{0}", Request.Form["password_modal"]); Customers custLogin = new Customers(txtModalCustEmail.Text, hashedPswd); string output = CustomersDB.GetCustomerLogin(custLogin); if (output == "1") { Session["custEmail"] = txtModalCustEmail.Text; Customers loggedCustomer = CustomersDB.GetCustomerbyEmail(Session["custEmail"].ToString()); Session["customerId"] = (int)loggedCustomer.CustomerId; Response.Redirect("CustomerRegistration.aspx"); } else { Control loginFail = FindControl("LoginFailure"); loginFail.Visible = true; string script = @"document.getElementById('" + LoginFailure.ClientID + "').innerHTML='Login failed, please check your credentials.' ;setTimeout(function(){document.getElementById('" + LoginFailure.ClientID + "').style.display='none';},5000);"; Page.ClientScript.RegisterStartupScript(this.GetType(), "somekey", script, true); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { Customers loggedCustomer = CustomersDB.GetCustomerbyEmail(Session["custEmail"].ToString()); Customers updatedCustomer = 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); try { bool updateSuccessful = CustomersDB.UpdateCustomer(loggedCustomer, updatedCustomer); if (updateSuccessful) { Control loginSuccess = FindControl("LoginSuccess"); loginSuccess.Visible = true; customerLogged.Text = "Welcome " + txtCustFirstName.Text; string script = @"document.getElementById('" + LoginSuccess.ClientID + "').innerHTML='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 information.' ;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(); } } }
protected void LoginButton(object sender, EventArgs e) { if (Page.IsValid) { string hashedPswd = HashPassword.ApplyHash(txtModalCustPassword.Text); // string custEmail = String.Format("{0}", Request.Form["email_modal"]); // string custPassword = String.Format("{0}", Request.Form["password_modal"]); Customers custLogin = new Customers(txtModalCustEmail.Text, hashedPswd); string output = CustomersDB.GetCustomerLogin(custLogin); if (output == "1") { Session["custEmail"] = txtModalCustEmail.Text; Customers loggedCustomer = CustomersDB.GetCustomerbyEmail(Session["custEmail"].ToString()); Session["customerId"] = (int)loggedCustomer.CustomerId; Response.Redirect("ItemsBought.aspx"); } else { Response.Write("Login Failed"); } } }
protected void Page_Load(object sender, EventArgs e) { HtmlControl loginIcon = (HtmlControl)Page.FindControl("mainBtnLogin"); HtmlControl loggedIcon = (HtmlControl)Page.FindControl("custLogged"); UnobtrusiveValidationMode = UnobtrusiveValidationMode.None; if (Session["custEmail"] != null) { loggedIcon.Visible = true; loginIcon.Visible = false; try { customerLogged.Text = "Welcome " + CustomersDB.confirmLogin(Session["custEmail"].ToString()); } catch (Exception) { ExceptionScript(); } } else { loggedIcon.Visible = false; loginIcon.Visible = true; } if (!IsPostBack) { try { Customers loggedCustomer = CustomersDB.GetCustomerbyEmail(Session["custEmail"].ToString()); txtCustFirstName.Text = loggedCustomer.CustFirstName; txtCustLastName.Text = loggedCustomer.CustLastName; txtCustAddress.Text = loggedCustomer.CustAddress; txtCustCity.Text = loggedCustomer.CustCity; ddlCustProv.Text = loggedCustomer.CustProv; txtCustPostal.Text = loggedCustomer.CustPostal; txtCustHomePhone.Text = loggedCustomer.CustHomePhone; txtCustBusPhone.Text = loggedCustomer.CustBusPhone; txtUnconfirmedEmail.Text = loggedCustomer.CustEmail; txtCustEmail.Text = loggedCustomer.CustEmail; customerLogged.Text = "Welcome " + txtCustFirstName.Text; } catch { ExceptionScript(); } } }
protected void validateEmailDB_ServerValidate(object source, ServerValidateEventArgs args) { Customers isEmailExisting = CustomersDB.GetCustomerbyEmail(txtCustEmail.Text); if (isEmailExisting == null) { args.IsValid = true; } else { args.IsValid = false; Control loginFail = FindControl("LoginFailure"); loginFail.Visible = true; string script = @"document.getElementById('" + LoginFailure.ClientID + "').innerHTML='Unable to register. A customer with that email address already exists.' ;setTimeout(function(){document.getElementById('" + LoginFailure.ClientID + "').style.display='none';},5000);"; Page.ClientScript.RegisterStartupScript(this.GetType(), "somekey", script, true); } }
protected void btnCancel_Click(object sender, EventArgs e) { try { Customers loggedCustomer = CustomersDB.GetCustomerbyEmail(Session["custEmail"].ToString()); txtCustFirstName.Text = loggedCustomer.CustFirstName; txtCustLastName.Text = loggedCustomer.CustLastName; txtCustAddress.Text = loggedCustomer.CustAddress; txtCustCity.Text = loggedCustomer.CustCity; ddlCustProv.Text = loggedCustomer.CustProv; txtCustPostal.Text = loggedCustomer.CustPostal; txtCustHomePhone.Text = loggedCustomer.CustHomePhone; txtCustBusPhone.Text = loggedCustomer.CustBusPhone; txtUnconfirmedEmail.Text = loggedCustomer.CustEmail; txtCustEmail.Text = loggedCustomer.CustEmail; } catch { ExceptionScript(); } }