Esempio n. 1
0
    //validates the users login
    //never included password into customer's required fields so instead it checks ID and email
    protected void CustomerLogin_Click(object sender, EventArgs e)
    {
        //retrieve input data
        clsCustomer tempCustomer = new clsCustomer();
        String      InputEmail   = CustomerEmailTextBox.Text;
        String      InputID      = CustomerIDTextBox.Text;
        String      error        = "";

        //validate email
        error = tempCustomer.ValidateEmail(InputEmail);

        //validate ID as number
        try { int testNum = Convert.ToInt32(InputID); }
        catch
        {
            error += "[!] Customer ID is not a valid number\n";
        }

        //if there is error output to error box
        if (error != "")
        {
            CustomerLoginErrorTextBoxOutput(error);
        }
        else
        {
            //attempt to find user
            // - if non-existent, output to error box
            // - otherwise set sessionCustomer to new customer
            bool exists = tempCustomer.Find(Convert.ToInt32(InputID));
            if (exists == true)
            {
                if (tempCustomer.email == InputEmail)
                {
                    //correct user
                    sessionCustomer = tempCustomer;
                    CustomerLoginErrorTextBoxOutput("Login Successful");
                    IdentificationLabel.Text = "Logged in as : " + sessionCustomer.name + " " + sessionCustomer.surname;
                    //store current user into session object
                    Session["newCustomer"] = sessionCustomer;
                }
                else
                {
                    CustomerLoginErrorTextBoxOutput("Email or ID are incorrect");
                }
            }
        }
    }
Esempio n. 2
0
        public void EmailValidTests()
        {
            //examples of valid emails
            clsCustomer newCustomer = new clsCustomer();

            String[] validEmails = new string[3]
            {
                "*****@*****.**",
                "*****@*****.**",
                "*****@*****.**"
            };
            bool outcome = false;

            foreach (String email in validEmails)
            {
                outcome |= !(newCustomer.ValidateEmail(email) == "");
            }
            Assert.AreEqual(outcome, false);
        }
Esempio n. 3
0
        public void EmailInvalidTests()
        {
            //examples of invalid emails
            clsCustomer newCustomer = new clsCustomer();

            String[] invalidEmails = new string[3]
            {
                "bob@example",
                "@examples.com",
                "clearly not"
            };
            bool outcome = false;

            foreach (String email in invalidEmails)
            {
                outcome |= !(newCustomer.ValidateEmail(email) == "");
            }
            Assert.AreNotEqual(outcome, false);
        }