Example #1
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            // The button to login for the various users.



            // This checks to see if any of the users are null
            // If they are not null, then the window is reset
            if (this._slpUser != null)
            {
                resetWindow();
                return;
            }
            if (this._teacherUser != null)
            {
                resetWindow();
                return;
            }
            if (this._managerUser != null)
            {
                resetWindow();
                return;
            }


            // Checking to see if the users are new users when they first log in
            try
            {
                string username  = txtUsername.Text;
                string password  = pwdPassword.Password;
                bool   isNewUser = pwdPassword.Password == "newuser";

                if (username.Length < 7 || username.Length > 255)
                {
                    MessageBox.Show("Your Username must the right length of characters. " +
                                    "Please try again.");
                    txtUsername.Focus();
                    return;
                }
                if (password.Length < 6)
                {
                    MessageBox.Show("Your password must be longer than 6 characters." +
                                    "Please try again.");
                    pwdPassword.Focus();
                    return;
                }

                if (cbxSLPUser.IsSelected == true)
                {
                    _slpUser = _userManager.AuthenticateSLP(username, password);
                }
                else if (cbxTeacherUser.IsSelected == true)
                {
                    _teacherUser = _userManager.AuthenticateTeacher(username, password);
                }
                else if (cbxManagerUser.IsSelected == true)
                {
                    _managerUser = _userManager.AuthenticateManager(username, password);
                }
                else if (cbxUserSelect.IsSelected == true)
                {
                    MessageBox.Show("You must select a user. Please select one and try logging in again.");
                }

                if (_slpUser != null)
                {
                    MessageBox.Show("Welcome back, " + _slpUser.FirstName + ", authentication successful.");

                    if (isNewUser)
                    {
                        this.Alert.Content = _slpUser.FirstName + ", this is your first login. You must change your password.";

                        var frmPassword = new frmUpdatePassword(_slpUser, _userManager, _teacherUser, _managerUser, true);
                        if (frmPassword.ShowDialog() == true)
                        {
                            MessageBox.Show("Password successful.");
                        }
                    }
                    setupWindow();
                    return;
                }
                else if (_teacherUser != null)
                {
                    if (_teacherUser != null)
                    {
                        MessageBox.Show("Welcome back, " + _teacherUser.FirstName + ", authentication successful.");

                        if (isNewUser)
                        {
                            this.Alert.Content = _teacherUser.FirstName + ", this is your first login. You must change your password.";

                            var frmPassword = new frmUpdatePassword(_slpUser, _userManager, _teacherUser, _managerUser, true);
                            if (frmPassword.ShowDialog() == true)
                            {
                                MessageBox.Show("Password successful.");
                            }
                        }
                        setupWindow();
                        return;
                    }
                }
                else if (_managerUser != null)
                {
                    if (_managerUser != null)
                    {
                        MessageBox.Show("Welcome back, " + _managerUser.FirstName + ", authentication successful.");

                        if (isNewUser)
                        {
                            this.Alert.Content = _managerUser.FirstName + ", this is your first login. You must change your password.";

                            var frmPassword = new frmUpdatePassword(_slpUser, _userManager, _teacherUser, _managerUser, true);
                            if (frmPassword.ShowDialog() == true)
                            {
                                MessageBox.Show("Password successful.");
                            }
                        }
                        setupWindow();
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Your username or password were incorrect. Please try again.");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.InnerException.Message);
            }
        }