protected void btnCreateAccount_Click(object sender, EventArgs e)
        {
            bool valid = false;

            user = new User(txtUsername.Text, txtPassword.Text);
            user.SetFirstName(txtFirstName.Text);
            user.SetLastName(txtLastName.Text);
            user.SetEmail(txtEmail.Text);

            Address address = new Address(txtAdress1.Text, txtAdress2.Text, txtCity.Text, txtState.Text, txtZipCode.Text);

            user.SetAddress(address);


            InputTypes[] totalTypes = { InputTypes.Username, InputTypes.FirstName, InputTypes.LastName, InputTypes.Email, InputTypes.FullAddress, InputTypes.Password, InputTypes.ConfirmPassword };
            v.SetUser(user);
            foreach (InputTypes type in totalTypes)
            {
                valid = v.IsValid(type);
                if (!valid)
                {
                    error.Add(type);
                }
            }


            if (valid && error.Count == 0)
            {
                Response.Redirect("Home.aspx");
            }
            else
            {
                //TODO: v.HandleErrors(error);
            }
        }
예제 #2
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            bool valid = false;

            user = new User(txtRegisterEmail.Text, txtRegisterPassword.Text);
            user.SetFirstName(txtRegisterFirstName.Text);
            v.SetUser(user);
            try
            {
                if (txtRegisterPassword.Text != txtRegisterConfirmPassword.Text)
                {
                    throw new ArgumentException("Please make sure your passwords match");
                }

                InputTypes[] modalTypes = { InputTypes.FirstName, InputTypes.Email, InputTypes.Password };
                foreach (InputTypes type in modalTypes)
                {
                    valid = v.IsValid(type);
                    if (!valid)
                    {
                        errors.Add(type);
                    }
                }

                if (v.EmailExists())
                {
                    throw new ArgumentException("This email already exists");
                }

                if (errors.Count == 0 && valid)
                {
                    Account.CreateAccount(user);
                    Int32 userId = Database.UserId(v.GetUser());
                    userInfo["isAuth"] = "true";
                    userInfo["userId"] = userId.ToString();
                    userInfo.Expires   = DateTime.Now.AddMinutes(10);
                    if (userId == 0)
                    {
                        throw new Exception("This user does not exist");
                    }
                    Response.Cookies.Add(userInfo);
                    Response.Redirect("Home.aspx");
                }
                else
                {
                    foreach (InputTypes error in errors)
                    {
                        if (error == InputTypes.FirstName)
                        {
                            throw new ArgumentException("Please make sure the first name field doesn't contain any numbers");
                        }
                    }
                    throw new ArgumentException("Please enter a valid input for each box");
                }
            }
            catch (ArgumentException ex)
            {
                alertBody.Text = "<div ID=\"alert\" class=\"alert alert-danger\"><div class:\"h3\"><strong> Registration Error </strong></div>" + ex.Message + "</div>";
            }
        }
예제 #3
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            v.SetUser(new User(txtUsername.Text, txtPassword.Text));

            bool userNameValid = v.IsValid(InputTypes.Username);
            bool passwordValid = v.IsValid(InputTypes.Password);


            if (userNameValid && passwordValid)
            {
                Response.Redirect("Home.aspx");
            }
            else
            {
                lblPasswordError.Text = "Please enter a valid Username/Password";
            }
        }