Esempio n. 1
0
        protected void btnSignIn_Click(object sender, EventArgs e)
        {
            // Validation Code
            // Set flag to false
            flgValidationError = false;

            // If built in validation finds an error
            //if (IsValid != true) { flgValidationError = true; }

            // ** Email validation **
            lblErrorEmail.Visible = false;
            // Check for blank email
            if (txtEmail.Text.Trim() == "")
            {
                lblErrorEmail.Visible = true;
                flgValidationError    = true;
                ValidationError.Display("Email address is blank");
            }
            else
            {
                // Check for valid email format
                if (GlobalClass.isValidEmail(txtEmail.Text) == false)
                {
                    lblErrorEmail.Visible = true;
                    flgValidationError    = true;
                    ValidationError.Display("Email address is formatted incorrectly");
                }
            }

            // ** Password validation **
            lblErrorPassword.Visible = false;
            // Check for blank password
            if (txtPassword.Text.Trim() == "")
            {
                lblErrorPassword.Visible = true;
                flgValidationError       = true;
                ValidationError.Display("Password is blank");
            }

            if (flgValidationError == true)
            {
                return;
            }

            // Try to sign in user
            if (SignInUser(txtEmail.Text, GlobalClass.encodePassword(txtPassword.Text)) == false)
            {
                flgValidationError = true;
                ValidationError.Display("Email address or Password is incorrect");
            }
            else
            {
                GlobalClass.checkFavorites();
                GlobalClass.logLogin("SignIn");

                if (Request.QueryString["page"] == "List")
                {
                    Response.Redirect("List.aspx");
                }
                else if (Request.QueryString["page"] == "Preferences")
                {
                    Response.Redirect("Preferences.aspx");
                }
                else if (Request.QueryString["page"] == "PreferencesReset")
                {
                    Response.Redirect("Preferences.aspx?page=PreferencesReset");
                }
                else
                {
                    Response.Redirect("Shopping.aspx");
                }
            }
        }
Esempio n. 2
0
        protected void btnCreateList_Click(object sender, EventArgs e)
        {
            // Validation Code
            // Set flag to false
            bool flgValidationError = false;

            // If built in validation finds an error
            //if (IsValid != true) { flgValidationError = true; }

            // ** Email validation **
            lblErrorEmail.Visible = false;
            // Check for blank email
            if (txtEmail.Text.Trim() == "")
            {
                lblErrorEmail.Visible = true;
                flgValidationError    = true;
                ValidationError.Display("Email address is blank");
            }
            else
            {
                // Check for valid email format
                if (GlobalClass.isValidEmail(txtEmail.Text) == false)
                {
                    lblErrorEmail.Visible = true;
                    flgValidationError    = true;
                    ValidationError.Display("Email address is formatted incorrectly");
                }
            }

            // ** Password validation **
            lblErrorPassword.Visible = false;
            // Check for blank password
            if (txtPassword.Text.Trim() == "")
            {
                lblErrorPassword.Visible = true;
                flgValidationError       = true;
                ValidationError.Display("Password is blank");
            }
            else
            {
                // Check for password lenght
                if (txtPassword.Text.Length < 6)
                {
                    lblErrorPassword.Visible = true;
                    flgValidationError       = true;
                    ValidationError.Display("Password needs to be longer");
                }
            }

            if (flgValidationError == true)
            {
                return;
            }

            // Check for unique email
            if (GlobalClass.isUniqueEmail(txtEmail.Text) == false)
            {
                lblErrorEmail.Visible = true;
                flgValidationError    = true;
                ValidationError.Display("A list already exisit for this email address, use the Sign in link below to see it");
            }
            else
            {
                // Create new user account
                string strUserId = System.Guid.NewGuid().ToString();
                if (CreateAccount(strUserId, txtEmail.Text, GlobalClass.encodePassword(txtPassword.Text)) == false)
                {
                    flgValidationError = true;
                    ValidationError.Display("Error creating account");
                }
                else
                {
                    Session["UserId"]      = strUserId;
                    Session["DisplayName"] = txtEmail.Text;
                    Session["FirstVisit"]  = "Yes";
                    Session["Favorites"]   = "1"; // new

                    // write coded user id cookie
                    //http://stackoverflow.com/questions/1093181/how-can-i-encrypt-a-cookie-content-in-a-simple-way-in-c-3-0
                    var plainBytes = Encoding.ASCII.GetBytes(strUserId);
                    var codedBytes = plainBytes;
                    Response.Cookies["timeout"].Value   = Convert.ToBase64String(codedBytes);
                    Response.Cookies["timeout"].Expires = DateTime.Now.AddDays(30);


                    CreateSampleItems(strUserId, 3, "Milk", 8, 3.49, 2, "Whole");
                    CreateSampleItems(strUserId, 1, "White Bread", 1, 1.25, 1, "Check for fresh");
                    CreateSampleItems(strUserId, 5, "Ice Cream", 4, 4, 0, "Gallon of Vanilla");
                    CreateSampleItems(strUserId, 3, "Ceddar Cheese", 7, 2, 1, "Small bag shredded");
                    CreateSampleItems(strUserId, 3, "Eggs", 8, 2.25, 1, "Large, Grade A");
                    CreateSampleItems(strUserId, 8, "Paper Towels", 0, 0, 1, "");
                    CreateSampleItems(strUserId, 2, "Ground Chuck", 1, 6.50, 1, "2 pounds");
                    CreateSampleItems(strUserId, 6, "Tomatoes", 10, 0, 3, "Get extra if they look good");
                    CreateSampleItems(strUserId, 1, "~", 0, 0, 0, "");

                    EmailWelcome(txtEmail.Text);
                    GlobalClass.logLogin("Home - New Account");
                    Response.Redirect("List.aspx");
                }
            }
        }