Beispiel #1
0
 private void mnuItemUpdatePassword_Click(object sender, RoutedEventArgs e)
 {
     // checks to see if the user is not null
     if (_user != null)
     {
         // if not opens the update password window
         var updatePassword = new frmUpdatePassword(_user, _userManager);
         updatePassword.ShowDialog();
     }
     else
     {
         // if null show that the users not logged in
         MessageBox.Show("You are not logged in.");
     }
 }
Beispiel #2
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if ((string)btnLogin.Content == "Login")
            {
                try
                {
                    _user = _userManager.AuthenticateUser(txtUserName.Text, pwdPassword.Password);

                    btnLogin.Content = "Logout";
                    txtUserName.Text = "";

                    if (pwdPassword.Password == "newuser")
                    {
                        var updatePassword = new frmUpdatePassword(_user, _userManager, true);

                        if (!updatePassword.ShowDialog() == true)
                        {
                            resetWindow();
                            _user = null;
                            return;
                        }
                    }

                    btnLogin.IsDefault      = false;
                    pwdPassword.Password    = "";
                    txtUserName.Visibility  = Visibility.Hidden;
                    lblUserName.Visibility  = Visibility.Hidden;
                    pwdPassword.Visibility  = Visibility.Hidden;
                    lblPassword.Visibility  = Visibility.Hidden;
                    sbarItemMessage.Content = "";


                    mnuMain.IsEnabled = true;
                    showUserTabs();
                    dgEmployeeList.ItemsSource = null;
                    try
                    {
                        var employeeManager = new EmployeeManager();

                        if (dgEmployeeList.ItemsSource == null)
                        {
                            dgEmployeeList.ItemsSource = employeeManager.RetrieveEmployeesByActive();

                            dgEmployeeList.Columns.Remove(dgEmployeeList.Columns[0]);
                            dgEmployeeList.Columns[0].Header = "Employee ID";
                            dgEmployeeList.Columns[1].Header = "Email Address";
                            dgEmployeeList.Columns[2].Header = "First Name";
                            dgEmployeeList.Columns[3].Header = "Last Name";
                            dgEmployeeList.Columns[4].Header = "Phone Number";
                            dgEmployeeList.Columns[5].Header = "Active";
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message);
                    }



                    sbarItemMessage.Content = "Welcome back, " + _user.FirstName;
                    if (_user.Roles.Count > 0)
                    {
                        var roleString = _user.Roles[0];
                        for (int i = 1; i < _user.Roles.Count; i++)
                        {
                            roleString += ", " + _user.Roles[i];
                        }

                        sbarItemMessage.Content = "You are logged in as: " + roleString;
                    }

                    else
                    {
                        sbarItemMessage.Content = "You have not yet been assigned a role.";
                    }
                }
                catch (Exception ex)
                {
                    pwdPassword.Clear();
                    txtUserName.Clear();
                    MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message);
                    txtUserName.Focus();
                }
            }
            else
            {
                _user = null;

                resetWindow();
                btnLogin.IsDefault = true;
            }
        }