private void Login()
        {
            try
            {
                int roleId = loginViewModel.GetLoginRole(UsernameTextBox.Text, Crypto.ConvertToHash(PasswordTextBox.Password));

                if (roleId > 0)
                {
                    // Report all action data
                    ActionLogger.ReportAllDataNow();

                    // Add login action to action logger
                    ActionLogger.Log(GetType().FullName + nameof(Login), UsernameTextBox.Text, roleId, $"<User_Login>");

                    // Open admin main view
                    foreach (Window window in Application.Current.Windows)
                    {
                        if (window.GetType() == typeof(MainWindow))
                        {
                            (window as MainWindow).MainContentControl.DataContext = new AdminMainView(roleId, UsernameTextBox.Text);
                        }
                    }
                }
                else
                {
                    NotifyInvalidLoginCredentials();
                }
            }
            catch
            {
                NotifyInvalidLoginCredentials();
            }
        }
Esempio n. 2
0
        public void ActionLogger_Log_TakesString_LogTextNotNull()
        {
            ActionLogger.Log("Test Location", "Test Username", 0, "Test Action Message");

            string actualResult = File.ReadAllText($"{Paths.TempDir}CSI_Action_Log_{DateTime.Today.ToString("MM-dd-yy")}.txt");

            Assert.IsNotNull(actualResult);
        }
Esempio n. 3
0
        public void ActionLogger_GetAllData_ReturnsNotNull()
        {
            // Log data to make sure there is always something there when this test is run
            ActionLogger.Log("Test Location", "Test Username", 0, "Test Action Message");

            var data = ActionLogger.GetAllData();

            Assert.IsNotNull(data);
        }
Esempio n. 4
0
        public void ActionLogger_Log_TakesString_CreatesLogFile()
        {
            ActionLogger.Log("Test Location", "Test Username", 0, "Test Action Message");

            bool actual   = File.Exists($"{Paths.TempDir}CSI_Action_Log_{DateTime.Today.ToString("MM-dd-yy")}.txt");
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 5
0
        private void LogoutButton_Click(object sender, RoutedEventArgs e)
        {
            ActionLogger.Log(GetType().FullName + nameof(LogoutButton_Click), UserRole, "<User_Logout>");

            foreach (Window window in Application.Current.Windows)
            {
                if (window.GetType() == typeof(MainWindow))
                {
                    (window as MainWindow).MainContentControl.DataContext = new MainView();
                }
            }
        }
        public void ImportUsers(Role userRole)
        {
            string csvFile = GetCsvPath();

            if (csvFile == null || csvFile.Trim() == "")
            {
                throw new FileFormatException();
            }
            if (!File.Exists(csvFile))
            {
                throw new FileNotFoundException($"{csvFile}");
            }
            else
            {
                string[] csvLines = File.ReadAllLines(csvFile);

                foreach (User user in GetUsers(csvLines))
                {
                    try
                    {
                        if (!RoleIsValid(user.RoleId))
                        {
                            throw new NotSupportedException("Invalid role ID!");
                        }
                        else if (UserNameExists(user.UserName))
                        {
                            AppendToLogFile($"Failed to create user. Username '{user.UserName}' is already in use!\n");
                        }
                        else if (EmailExists(user.Email))
                        {
                            AppendToLogFile($"Failed to create user. Email '{user.Email}' is already in use!\n");
                        }
                        else
                        {
                            ActionLogger.Log(GetType().FullName + nameof(ImportUsers), userRole, $"<Importing_User UserName={user.UserName}, Email={user.Email}, RoleId={user.RoleId}>");
                            database.CreateUser(user);
                            AppendToLogFile($"User '{user.UserName}' created!\n");
                        }
                    }
                    catch (Exception ex)
                    {
                        AppendToLogFile($"Error creating user '{user.UserName}'. Error={ex.Message}\n");
                    }
                }
            }
            MessageBox.Show("User import complete! An import results file has been generated and placed on your desktop.", "", MessageBoxButton.OK);
        }
Esempio n. 7
0
 private void DeleteUsers(List <User> usersToDelete)
 {
     try
     {
         // delete user from data base and remove it from the grid
         foreach (User user in usersToDelete)
         {
             ActionLogger.Log(GetType().FullName + nameof(UsersDataGridContextMenu_Click), userRole, $"<Delete_User> UserName={user.UserName}, Email={user.Email}, Role={user.RoleId}");
             database.DeleteUser(user.UserName);
             UsersDataGrid.Items.Remove(user);
         }
     }
     catch (Exception ex)
     {
         Error.ReportOrLog(ex);
     }
 }
Esempio n. 8
0
        //
        // Import users from a CSV file
        //

        private void ImportUsersButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ActionLogger.Log(GetType().FullName + nameof(ImportUsersButton_Click), userRole, "<Import_Users_Start>");
                usersViewModel.ImportUsers(userRole);
                RefreshGrid();
            }
            catch (FileNotFoundException ex)
            {
                MessageBox.Show($"Cannot find path to file '{ex.Message}'", "File Not Found", MessageBoxButton.OK);
            }
            catch (FileFormatException)
            {
            }
            catch (Exception ex)
            {
            }
            finally
            {
                ActionLogger.Log(GetType().FullName + nameof(ImportUsersButton_Click), userRole, "<Import_Users_End>");
            }
        }
Esempio n. 9
0
        private void TryCreateUser()
        {
            try
            {
                ActionLogger.Log(GetType().FullName + nameof(TryCreateUser), userRole, $"<Creating_User UserName={UserNameTextBox.Text}, Email={EmailTextBox.Text}, RoleId={RoleTextBox.Text}>");

                if (usersViewModel.UserNameExists(UserNameTextBox.Text))
                {
                    MessageBox.Show("This username exists already!", "", MessageBoxButton.OK);
                }
                else if (usersViewModel.EmailExists(EmailTextBox.Text))
                {
                    MessageBox.Show("This email exists already!", "", MessageBoxButton.OK);
                }
                else
                {
                    bool created = usersViewModel.CreateUser(UserNameTextBox.Text, Crypto.ConvertToHash(PasswordTextBox.Text), EmailTextBox.Text, RoleTextBox.SelectedIndex, 0);

                    if (created)
                    {
                        MessageBox.Show("User Created!", "", MessageBoxButton.OK);
                        UserNameTextBox.Text      = "";
                        PasswordTextBox.Text      = "";
                        EmailTextBox.Text         = "";
                        RoleTextBox.SelectedIndex = 0;
                    }
                    else
                    {
                        MessageBox.Show("Error Creating User!", "", MessageBoxButton.OK);
                    }
                }
            }
            catch (Exception ex)
            {
                Error.ReportOrLog(ex);
            }
        }