Ejemplo n.º 1
0
        /// <summary>
        /// Event handler for button click in <see cref="CreateAccountWindow"/>.
        /// <para>When Submit is clicked, the text fields check to make sure valid data is entered
        /// using regular expressions in <see cref="util.RegexUtilities"/></para>
        /// </summary>
        ///
        private void CreateAccountSubmitButton_Click(object sender, RoutedEventArgs e)
        {
            #region TextField Error Checking
            String errorMessage = null;
            if (string.IsNullOrWhiteSpace(this.firstNameTextBox.Text))
            {
                errorMessage += " \"First Name\" ";
            }

            if (string.IsNullOrWhiteSpace(this.lastNameTextBox.Text))
            {
                errorMessage += " \"Last Name\" ";
            }

            if (string.IsNullOrWhiteSpace(this.emailTextBox.Text))
            {
                errorMessage += " \"Email\" ";
            }

            if (string.IsNullOrWhiteSpace(this.userPasswordBox.Password))
            {
                errorMessage += " \"Password\" ";
            }

            if (string.IsNullOrWhiteSpace(this.confirmUserPasswordBox.Password))
            {
                errorMessage += " \"Password\" ";
            }
            else if (this.confirmUserPasswordBox.Password != this.userPasswordBox.Password)
            {
                MessageBox.Show("Password do not match. Please try again.", "Invalid Password", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (!(errorMessage == null))
            {
                MessageBox.Show($"{errorMessage} field(s) missing value", "Invalid Fields", MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }
            #endregion
            #region Regular Expression Checks

            if (!util.RegexUtilities.IsValidEmail(this.emailTextBox.Text))
            {
                this.emailTextBox.Focus();
            }


            if (!util.RegexUtilities.IsValidPhoneNumber(this.phoneTextBox.Text))
            {
                this.phoneTextBox.Focus();
            }

            if (!util.RegexUtilities.IsValidPassword(this.userPasswordBox.Password))
            {
                this.userPasswordBox.Focus();
            }

            if (this.userPasswordBox.Password != this.confirmUserPasswordBox.Password)
            {
                this.lblConfirmPassword.Visibility = Visibility.Visible;
                this.confirmUserPasswordBox.Focus();
            }

            if (!util.RegexUtilities.IsValidName(this.firstNameTextBox.Text))
            {
                this.firstNameTextBox.Focus();
            }

            if (!util.RegexUtilities.IsValidName(this.lastNameTextBox.Text))
            {
                this.lastNameTextBox.Focus();
            }

            #endregion
            #region Create a user
            //If all the data is valid...
            if (util.RegexUtilities.IsValidPhoneNumber(this.phoneTextBox.Text) &&
                util.RegexUtilities.IsValidName(this.firstNameTextBox.Text) &&
                util.RegexUtilities.IsValidName(this.lastNameTextBox.Text) &&
                util.RegexUtilities.IsValidEmail(this.emailTextBox.Text) &&
                util.RegexUtilities.IsValidPhoneNumber(this.phoneTextBox.Text) &&
                util.RegexUtilities.IsValidPassword(this.userPasswordBox.Password) &&
                this.userPasswordBox.Password == this.confirmUserPasswordBox.Password)
            {
                //New instance of encryption class
                util.HashManager encrypter = new util.HashManager();

                util.UserData newUser = new util.UserData {
                    //Encrypt user data and set to newUser object
                    FirstName              = this.firstNameTextBox.Text.ToUpper(),
                    LastName               = this.lastNameTextBox.Text.ToUpper(),
                    Email                  = encrypter.HashTextSHA256(this.emailTextBox.Text),
                    PhoneNumber            = encrypter.HashTextSHA256(this.phoneTextBox.Text),
                    Password               = encrypter.HashUniqueTextSHA256(this.userPasswordBox.Password),
                    SecurityQuestion       = this.securityQuestionComboBox.Text,
                    SecurityQuestionAnswer = encrypter.HashTextSHA256(this.securityQuestionTextBox.Text)
                };

                // SQL Connection String
                string connectionString = DatabaseConnection.GetConnectionString();


                // Open database connection and send that data to the database hashed.
                DatabaseConnection dbConnection = new DatabaseConnection(connectionString);

                // checks if account exists.
                if (dbConnection.CheckAccountExists(newUser.Email, newUser.Password))
                {
                    MessageBox.Show("Account already exists with this email", "Account Exists",
                                    MessageBoxButton.OK, MessageBoxImage.Asterisk);
                    return;
                }
                else
                {
                    var questionnaire = new QuestionaireWindow(ref newUser);
                    // If you do not press finish, show the dialog again.
                    while (questionnaire.ShowDialog() == false)
                    {
                        questionnaire = new QuestionaireWindow(ref newUser,
                                                               "Please press finish to confirm your account.");
                    }
                }

                try {
                    if (dbConnection.AddUserToDatabase(newUser))
                    {
                        LoginWindow loginWindow = new LoginWindow();
                        this.windowSettings.TransitionScreen(loginWindow, this);
                    }
                } catch (SqlException) {
                    throw new Exception();
                }
            }
            #endregion
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Event handler for GoBackButton click in <see cref="CreateAccountWindow"/>.
        /// <para>When GoBack is clicked, the window goes back to the
        /// login screen <see cref="window.CreateAccountWindow"/></para>
        /// </summary>
        ///
        private void GoBackButton_Click(object sender, RoutedEventArgs e)
        {
            Window window = new LoginWindow();

            this.windowSettings.TransitionScreen(window, this);
        }