Example #1
0
        protected void View_Init(object sender, EventArgs e)
        {
            // *** Auto Log In Code ***
            string svUserId      = (string)(Session["UserId"]);
            string svDisplayName = (string)(Session["DisplayName"]);

            // If one of the session vars is empty -- Meaning NOT logged in
            if ((string.IsNullOrEmpty(svUserId) == true) || (string.IsNullOrEmpty(svDisplayName) == true))
            {
                // Try to get UserId from Cookie
                string strUserId = GlobalClass.readUserIdFromCookie();
                if (strUserId != null)
                {
                    // If valid User Id try to look up User in DB & populate session vars
                    if (GlobalClass.getUserInfo(strUserId) == true)
                    {
                        svDisplayName = (string)(Session["DisplayName"]);
                        GlobalClass.checkFavorites();
                        GlobalClass.logLogin("Shopping");
                    }
                    else
                    {
                        Response.Redirect("SignIn.aspx");
                    }
                }
                else
                {
                    // If session vars do not have valid values then back to the home page
                    Response.Redirect("SignIn.aspx");
                }
            }

            lblDisplayName1.Text = svDisplayName;
            lblDisplayName2.Text = svDisplayName;
            // *** Auto Log In Code ***

            if (IsPostBack == false)
            {
                LoadSendTo();
            }
            LoadGrid();
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Request.Browser["IsMobileDevice"] == "true")
            //{
            //    Response.Redirect("MobileShopping.aspx");
            //}
            //else
            //{
            //    Response.Redirect("Home.aspx");
            //}

            // *** Auto Log In Code ***
            string svUserId      = (string)(Session["UserId"]);
            string svDisplayName = (string)(Session["DisplayName"]);

            // If one of the session vars is empty -- Meaning NOT logged in
            if ((string.IsNullOrEmpty(svUserId) == true) || (string.IsNullOrEmpty(svDisplayName) == true))
            {
                // Try to get UserId from Cookie
                string strUserId = GlobalClass.readUserIdFromCookie();
                if (strUserId != null)
                {
                    // If valid User Id try to look up User in DB & populate session vars
                    if (GlobalClass.getUserInfo(strUserId) == false)
                    {
                        Response.Redirect("Home.aspx");
                    }
                }
                else
                {
                    // If session vars do not have valid values then back to the home page
                    Response.Redirect("Home.aspx");
                }
            }

            GlobalClass.checkFavorites();
            GlobalClass.logLogin("Default");
            Response.Redirect("Shopping.aspx");
            // *** Auto Log In Code ***
        }
Example #3
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");
                }
            }
        }
Example #4
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");
                }
            }
        }