diff --git a/Source Code/.vscode/launch.json b/Source Code/.vscode/launch.json new file mode 100644 index 0000000..c4a836b --- /dev/null +++ b/Source Code/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/main/bin/Debug/net6.0/main.dll", + "args": [], + "cwd": "${workspaceFolder}/main", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/Source Code/.vscode/tasks.json b/Source Code/.vscode/tasks.json new file mode 100644 index 0000000..2754b32 --- /dev/null +++ b/Source Code/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/main/main.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/main/main.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/main/main.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs index 256ce31..2eee2fe 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs @@ -12,6 +12,10 @@ namespace TeamHobby.HobbyProjectGenerator.Archive _conn = dataSource; } + //public IDataSource GetConnection() + //{ + // return _conn; + //} // Create the folder where the compress file will be stored public bool CreateArchiveFolder(){ @@ -22,18 +26,25 @@ namespace TeamHobby.HobbyProjectGenerator.Archive // Find the root drive of the program string drive = Path.GetPathRoot(path: curPath); // Check if Drive exists or not - if (!Directory.Exists(drive)) - { - Console.WriteLine("Drive {0} not found", drive); - return false; - } + try { + if (!Directory.Exists(drive)) + { + Console.WriteLine("Drive {0} not found", drive); + return false; + } - string archiveFolder = curPath + folderName; - //Console.WriteLine("Creating a new folder at: {0}", archiveFolder); - if (!Directory.Exists(archiveFolder)) - { - Console.WriteLine("Creating a new folder at: {0}", archiveFolder); - Directory.CreateDirectory(archiveFolder); + string archiveFolder = curPath + folderName; + //Console.WriteLine("Creating a new folder at: {0}", archiveFolder); + if (!Directory.Exists(archiveFolder)) + { + Console.WriteLine("Creating a new folder at: {0}", archiveFolder); + Directory.CreateDirectory(archiveFolder); + //return true; + } + } + catch (Exception ex){ + // If the creating a folder failed, return false + return false; } return true; } @@ -91,7 +102,11 @@ namespace TeamHobby.HobbyProjectGenerator.Archive if (_conn.GetType() == typeof(SqlDAO)) { sqlDS = (SqlDAO)_conn; + } + // Check to make sure that Sql Data source connection is not null + if (sqlDS == null){ + return false; } // TODO: Remember to add try catch block here to make sure it is completed. @@ -103,11 +118,11 @@ namespace TeamHobby.HobbyProjectGenerator.Archive Console.WriteLine(""); // Creating a file name: - string filePath = @"C:\HobbyArchive"; + //string filePath = @"C:\HobbyArchive"; //Console.WriteLine("Creating file name ... "); //string curPath = archive.CreateOutFileName(); Console.WriteLine("Creating Output file name ..."); - string curPath = CreateOutFileName(); + string outPath = CreateOutFileName(); Console.WriteLine("Output file name created ..."); Console.WriteLine("----------------"); Console.WriteLine(""); @@ -116,46 +131,63 @@ namespace TeamHobby.HobbyProjectGenerator.Archive //string pathTemp = "C:/Temp/oldlogs10.txt"; //string pathTempBack = @"C:\Temp\oldlogs10.txt"; - //Output SQL to a text file - Console.WriteLine("Copying to a text file ..."); - sqlDS.CopyToFile(curPath); - Console.WriteLine("Copying completed ..."); - Console.WriteLine("----------------"); - Console.WriteLine(""); + // Try catch block to delete abort the compressing process + try{ + //Output SQL to a text file + Console.WriteLine("Copying to a text file ..."); + sqlDS.CopyToFile(outPath); + Console.WriteLine("Copying completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); - // Compress the file - Console.WriteLine("Copressing the text file ..."); - sqlDS.CompressFile(curPath); - Console.WriteLine("Copression completed ..."); - Console.WriteLine("----------------"); - Console.WriteLine(""); + // Compress the file + Console.WriteLine("Copressing the text file ..."); + sqlDS.CompressFile(outPath); + Console.WriteLine("Copression completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); - //Remove output file - Console.WriteLine("Removing the text file ..."); - sqlDS.RemoveOutputFile(curPath); - Console.WriteLine("Text File removal completed ..."); - Console.WriteLine("----------------"); - Console.WriteLine(""); + //Remove output file + Console.WriteLine("Removing the text file ..."); + sqlDS.RemoveOutputFile(outPath); + Console.WriteLine("Text File removal completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); - // Remove entries fromt the database - Console.WriteLine("Removing the text file ..."); - sqlDS.RemoveEntries(); - Console.WriteLine("Entries removal completed ..."); - Console.WriteLine("----------------"); - Console.WriteLine(""); + // Remove entries fromt the database + Console.WriteLine("Removing the text file ..."); + sqlDS.RemoveEntries(); + Console.WriteLine("Entries removal completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); + + // Return true if compressing sequence is successful + return true; + } + catch (Exception e){ + // Abort the compressing sequence and clean up uneccesary files. + Console.WriteLine("Archiving Sequenced failed. Cleaning up resources."); + + // Delete the text output file if any of the process failed + if (File.Exists(outPath)){ + File.Delete(outPath); + } + + // Delete the compressed file if Removing entries and removing text file output failed + string compFile = outPath + ".gz"; + if (File.Exists(compFile)){ + File.Delete(compFile); + } + + return false; + + } // Testing date time patters //string date = DateTime.Now.ToString("d"); //Console.WriteLine(date); //Console.WriteLine(DateTime.Now.ToString("M_d_yyyy_H:mm:ss")); - - return true; - } - - - - } } \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs new file mode 100644 index 0000000..88e7b50 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeamHobby.HobbyProjectGenerator.Archive; +using TeamHobby.HobbyProjectGenerator.DataAccess; + +namespace TeamHobby.HobbyProjectGenerator.ArchiveTests +{ + public class ArchivingTests + { + //private string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + + // "SERVER=localhost;" + + // "DATABASE=hobby;" + + // "UID=root;" + + // "PASSWORD=Teamhobby;" + + // "OPTION=3"; + + + // [TestMethod] + public void IsArchiveFolderCreated(IDataSource sqlDAO) + { + // Arrange + //SqlDAO sqlDAO = new SqlDAO(dbInfo); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + string folderPath = @"C:/HobbyArchive"; + bool expectedVal = true; + + // Act + archiveManager.CreateArchiveFolder(); + + + // Assert + bool actualVal = Directory.Exists(folderPath); + if (expectedVal == actualVal) + { + Console.WriteLine("Expected: {0}, Actual: {1}. Folder created correctly", expectedVal, actualVal); + try + { + Directory.Delete(folderPath, true); + } + catch { + Console.WriteLine("Folder failed to be deleted"); + } + } + else + { + Console.WriteLine("Expected: {0}, Actual: {1}. Folder created incorrectly", expectedVal, actualVal); + } + } + + // [TestMethod] + public void IsFileNameCreated(IDataSource sqlDAO) + { + // Arrange + string foldPath = @"C:\HobbyArchive"; + string fileName = DateTime.Now.ToString("M_d_yyyy") + "_archive.csv"; + string expectedFilePath = System.IO.Path.Combine(foldPath, fileName); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + + // Act + string actualFilePath = archiveManager.CreateOutFileName(); + + // Assert + bool result = String.Equals(actualFilePath, expectedFilePath); + if (result) + { + Console.WriteLine("Expected: {0}, Actual: {1}. File name created correctly", expectedFilePath, actualFilePath); + } + else + { + Console.WriteLine("Expected: {0}, Actual: {1}. File name created incorrectly", expectedFilePath, actualFilePath); + } + + } + + public void CopyingToAFileTest(IDataSource sqlDAO) + { + // Arrange + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + SqlDAO sqlDS = null; + + if (sqlDAO.GetType() == typeof(SqlDAO)) + { + sqlDS = (SqlDAO)sqlDAO; + } + + // Act + + + // Assert + + } + + public static void Main(string[] args) + { + string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + + "SERVER=localhost;" + + "DATABASE=hobby;" + + "UID=root;" + + "PASSWORD=Teamhobby;" + + "OPTION=3"; + SqlDAO sqlDAO = new SqlDAO(dbInfo); + //ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + + // Testing folder creation + ArchivingTests test = new ArchivingTests(); + test.IsArchiveFolderCreated(sqlDAO); + Console.WriteLine("-----------------"); + Console.WriteLine(""); + + // Testing file creation + test.IsFileNameCreated(sqlDAO); + Console.WriteLine("-----------------"); + Console.WriteLine(""); + + + } + + } + +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj new file mode 100644 index 0000000..560115c --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 1843b50..7a14a05 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -17,9 +17,9 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess public SqlDAO(string info) { try { - Console.WriteLine("Establising Connection"); + Console.WriteLine("Establising Connection..."); _conn = new OdbcConnection(info); - Console.WriteLine("Connection established"); + Console.WriteLine("Connection established."); } catch { //_conn = null; @@ -31,7 +31,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess // Getter and setter for Odbc public OdbcConnection Connection { get; set; } - public OdbcConnection getConnection() + public OdbcConnection GetConnection() { return _conn; } @@ -149,7 +149,6 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess // Get the stream of the original file using FileStream origFile = File.Open(fileName, FileMode.Open); - // Get the attribute of the file FileAttributes atrribute = File.GetAttributes(fileName); @@ -161,15 +160,16 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress); origFile.CopyTo(compressor); - return true; + return true; } return false; } catch (Exception ex) { + Console.WriteLine("Error when compressing a file !!, will be handled higher up the call stack"); Console.WriteLine(ex.Message); - return false; + throw; } } @@ -204,10 +204,10 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess return true; } - catch - { + catch (Exception ex) + { _conn.Close(); - Console.WriteLine("Error when copying query to a file !!"); + Console.WriteLine("Error when copying query to a file !!, will be handled higher up the call stack"); throw; } finally @@ -229,7 +229,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } catch { Console.WriteLine("Removing file failed!!"); - return false; + throw; } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/UiPrint.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/UiPrint.cs new file mode 100644 index 0000000..e197fbb --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/UiPrint.cs @@ -0,0 +1,39 @@ +// Print Statements used throughout the program. + +namespace TeamHobby.HobbyProjectGenerator.DataAccess +{ + public class UiPrint + { + public void InitialMenu() + { + // Create intial menu + Console.WriteLine("What would you like to access?"); + int num = 1; + Console.WriteLine(num + ".User Management"); + num += 1; + Console.WriteLine(num + ".Logging"); + } + public void UserManagementMenu(string username) + { + // Menu for all UserManagement options + int menu = 0; + Console.WriteLine($"Welcome {username} to User Management.\n"); + Console.WriteLine("What would you like to do?\n"); + Console.WriteLine(menu + ") To exit User Management.\n"); + menu += 1; + Console.WriteLine(menu + ") Create a new account.\n"); + menu += 1; + Console.WriteLine(menu + ") Edit an account.\n"); + menu += 1; + Console.WriteLine(menu + ") Delete an account.\n"); + menu += 1; + Console.WriteLine(menu + ") Disable an account.\n"); + menu += 1; + Console.WriteLine(menu + ") Enable an account.\n"); + menu += 1; + Console.WriteLine(menu + ") View logs.\n"); + menu += 1; + Console.WriteLine(menu + ") View archive.\n"); + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs index 902cba9..198f16c 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs @@ -3,10 +3,79 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Data.Odbc; +using TeamHobby.HobbyProjectGenerator.DataAccess; namespace TeamHobby.HobbyProjectGenerator.UserManagement { - internal class AccountService + public class AccountService { + public bool CreateUserRecord(UserAccount newUser, string CreatedBy, IDataSource dbSource) + { + try + { + // Insert into users table + string sqlUser = $"INSERT INTO users (UserName, Password, Role, IsActive," + + $"CreatedBy, CreatedDate, Email) VALUES ('{newUser.username}', " + + $"'{newUser.password}','{newUser.role}', 1," + + $"'{CreatedBy}', NOW(),'{newUser.email}');"; + + bool insertNewUser = dbSource.WriteData(sqlUser); + return insertNewUser; + + } + catch (Exception ex) + { + return false; + } + } + public bool EditUserRecord(UserAccount newUser, string CreatedBy, IDataSource dbSource) + { +/* // Insert into users table + string sqlUser = $"UPDATE hobby.roles r SET r.Role = 'regular',r.CreatedBy = 'colin'WHERE r.RoleID = 5; "; + + Object insertNewUser = dbSource.WriteData(sqlUser); + // Insert into users table + string sqlRoles = $"INSERT INTO roles (Role, CreatedBy, CreatedDate) " + + $"VALUES ('{newUser.NewRole}', '{CreatedBy}', NOW());"; + Object insertNewRole = dbSource.WriteData(sqlUser); + // Create string for confirming user account + string confirmUser = $"Select * from users where username = {newUser.NewUserName} " + + $"and password = {newUser.NewPassword};"; + Object conUser = dbSource.ReadData(confirmUser); + + //Console.WriteLine("type of Reesult:" + confirmAdmin.GetType()); + OdbcDataReader reader = null; + + if (conUser.GetType() == typeof(OdbcDataReader)) + { + reader = (OdbcDataReader)conUser; + } + + // Read Sql query results + while (reader.Read()) + { + Console.WriteLine(reader.GetString(0)); + } + + SqlDAO sqlDS = (SqlDAO)dbSource; + Console.WriteLine(""); + + // Closing the connection + sqlDS.getConnection().Close();*/ + return true; + } + public bool DeleteUserRecord(UserAccount newUser, IDataSource dbSource) + { + return true; + } + public bool DisableUser(UserAccount newUser, IDataSource dbSource) + { + return true; + } + public bool EnableUser(UserAccount newUser, IDataSource dbSource) + { + return true; + } } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs index 1939d51..28d621e 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Data.Odbc; using TeamHobby.HobbyProjectGenerator.UserManagement; -using TeamHobby.HobbyProjectGenerator.Implementations; +using TeamHobby.HobbyProjectGenerator.DataAccess; namespace TeamHobby.HobbyProjectGenerator.UserManagement { @@ -13,125 +14,257 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement public string IsInputValid(string checkUN, string checkPWD) { // Create bool variables to check if username and password are valid - bool ValidUN = checkUN.All(un => Char.IsLetterOrDigit(un) || un == '@' + bool validUN = checkUN.All(un=>Char.IsLetterOrDigit(un) || un=='@' || un == '.' || un == ',' || un == '!'); - bool ValidPwd = checkPWD.All(Char.IsLetterOrDigit); + bool validPwd = checkPWD.All(Char.IsLetterOrDigit); + // Check if any are empty if (checkUN == null || checkPWD == null) { return "Invalid input\n"; } + // Check if username is within the restricted length else if (checkUN.Length > 15 || checkUN.Length <= 0 - || ValidUN is false) + || validUN is false) { return "Invalid Username\n"; } + // Check if password is within the restricted length else if (checkPWD.Length > 18 || checkPWD.Length <= 0 - || ValidPwd is false) + || validPwd is false) { return "Invalid Password\n"; } + // Check if username and password are valid else if (checkUN.Length <= 15 && checkUN.Length > 0 - || ValidUN is true && checkPWD.Length <= 18 - && checkPWD.Length > 0 || ValidPwd is true) + && validUN is true && checkPWD.Length <= 18 + && checkPWD.Length > 0 && validPwd is true) { return "Username and password is valid.\n"; } + // Check if username and password and email are valid else if (checkUN.Length <= 15 && checkUN.Length > 0 - || ValidUN is true) + && validUN is true && checkPWD.Length <= 18 + && checkPWD.Length > 0 && validPwd is true) + { + return "Username and password is valid.\n"; + } + // For testing to make sure username is valid + else if (checkUN.Length <= 15 && checkUN.Length > 0 + && validUN is true) { return "Valid Username\n"; } + // For testing to make sure password is valid else if (checkPWD.Length <= 18 && checkPWD.Length > 0 - || ValidPwd is true) + && validPwd is true) { return "Valid Password\n"; } else { - return "Invalid Input\n"; + return "Invalid input\n"; } } - public bool isAdmin() + public string IsInputValid(string checkUN, string checkPWD, string email, string role) { - return false; - } - public void CreateUserRecord(UserAccount user) - { - Console.Write(IsInputValid(user.username, user.password)); + // Create bool variables to check if username and password and email are valid + bool validUN = checkUN.All(un => Char.IsLetterOrDigit(un) || un == '@' + || un == '.' || un == ',' || un == '!'); - } + bool validPwd = checkPWD.All(Char.IsLetterOrDigit); + bool validEmail = email.All(email => Char.IsLetterOrDigit(email) && email == '@' + && email == '.'); + bool validRole = role.All(role => Char.IsLetter(role)); - /*public NewUserName() - { - - } - public NewPassword() - { - // Create bool value for password confirm loop - bool conPsswrd = true; - // Loop until password is confirmed - while (conPsswrd == true) + // Check if any are empty + if (checkUN == null || checkPWD == null || email == null) { - // Confirm Password - Console.WriteLine("Please re-enter the password:"); - string checkPsswd = Console.ReadLine(); - // Check if passwords match - if (userPassword == checkPsswd) - { - // Get Security question for password reset - Console.WriteLine("Please enter a security question.\n" + - "(EX: What is your favorite food?"); - string SecQuest = Console.ReadLine(); - // Get Security question answer - Console.WriteLine("Please enter the answer for your security question:"); - String SecAnswer = Console.ReadLine(); + return "Invalid input\n"; + } + // Check if username is within the restricted length + else if (checkUN.Length > 15 || checkUN.Length <= 0 + || validUN is false) + { + return "Invalid Username\n"; + } + // Check if password is within the restricted length + else if (checkPWD.Length > 18 || checkPWD.Length <= 0 + || validPwd is false) + { + return "Invalid Password\n"; + } + // Check if email is within the restricted length + else if (email.Length > 18 || email.Length <= 0 + || validEmail is false) + { + return "Invalid Email.\n"; + } + // Check if username and password are valid + else if (checkUN.Length <= 15 && checkUN.Length > 0 + && validUN is true && checkPWD.Length <= 18 + && checkPWD.Length > 0 && validPwd is true) + { + return "Username and password is valid.\n"; + } + // Check if username and password and email are valid + else if (checkUN.Length <= 15 && checkUN.Length > 0 + && validUN is true && checkPWD.Length <= 18 + && checkPWD.Length > 0 && validPwd is true + && email.Length > 18 && email.Length <= 0 + && validEmail is true) + { + return "Username and password is valid.\n"; + } + // For testing to make sure username is valid + else if (checkUN.Length <= 15 && checkUN.Length > 0 + && validUN is true) + { + return "Valid Username\n"; + } + // For testing to make sure password is valid + else if (checkPWD.Length <= 18 && checkPWD.Length > 0 + && validPwd is true) + { + return "Valid Password\n"; + } + // For testing to make sure email is valid + else if (email.Length > 18 && email.Length <= 0 + && validEmail is true) + { + return "Valid Password\n"; + } + else + { + return "Invalid input\n"; + } + } + // Check with database if user is an admin + public bool isAdmin(UserAccount user, IDataSource dbSource) + { + // string checkAdmin = $"Select * from users where username = {user.username} and password = {user.password};"; + string checkAdmin = $"select r.Role from roles r, users u where " + + $"UserName = '{user.username}' and Password = '{user.password}' and r.Role = u.Role;"; + Object confirmAdmin = dbSource.ReadData(checkAdmin); + //Console.WriteLine("type of Reesult:" + confirmAdmin.GetType()); + OdbcDataReader reader = null; - // Call user manager method to create the new user - //int userCreateConfirm = new CreateUser(userName,userPassword,SecQuest,SecAnswer); + if (confirmAdmin.GetType() == typeof(OdbcDataReader)) + { + reader = (OdbcDataReader)confirmAdmin; + } - // Check if user creation was successful - /*if (userCreateConfirm = 1) + // Create String to hold sql output + string checkSql = ""; + + // Read Sql query results + while (reader.Read()) + { + checkSql = reader.GetString(0); + } + + SqlDAO sqlDS = (SqlDAO)dbSource; + Console.WriteLine(""); + + // Closing the connection + sqlDS.getConnection().Close(); + + if (checkSql == "Admin") + { + return true; + } + else + { + return false; + } + } + public string CreateUserRecord(UserAccount user, IDataSource dbSource) + { + // Check Login inputs + IsInputValid(user.username, user.password); + + bool Admin = isAdmin(user, dbSource); + + // Give access if the user is and Admin + if (Admin is false) + { + return "Access Denied: Unauthorized\n"; + } + else + { + // db.users layout (UserName, Password, RoleID, IsActive, CreatedBy, CreatedDate) + // db.roles layout (RoleID(AutoGen), Role, CreatedBy, CreatedDate) + // Create UiPrint Object + UiPrint ui = new UiPrint(); + // Create Account Service object + AccountService accountService = new AccountService(); + // Create credentials object for new inptus + GetCredentials newCredentials = new GetCredentials(); + // Print User Management menu + ui.UserManagementMenu(user.username); + // Create bool object for menu loop + bool menuLoop = true; + // Create loop for menu + while (menuLoop is true) { + // Get user choice + int menuChoice = Convert.ToInt32(Console.ReadLine()); + // Complete the appropriate action + switch (menuChoice) { - - // Confirm to user that the account has been created - Console.WriteLine("Account created succesfully with the username of" + userName); + // Exit menu + case 0: + return "Exiting UserManagement.\n"; + break; + // Create account + case 1: + UserAccount newUser = new UserAccount(newCredentials.GetUserName(), + newCredentials.GetPassword(), newCredentials.GetEmail(), + newCredentials.GetRole(), DateTime.UtcNow); + accountService.CreateUserRecord(newUser,user.username, dbSource); + break; + // Edit account + case 2: + /* UserAccount newEditUser = new UserAccount(newCredentials.GetUserName(), + newCredentials.GetPassword(), DateTime.UtcNow); + accountService.EditUserRecord(newEditUser, dbSource);*/ + break; + // Delete account + case 3: + UserAccount newDeleteUser = new UserAccount(newCredentials.GetUserName(), + newCredentials.GetPassword(), DateTime.UtcNow); + accountService.DeleteUserRecord(newDeleteUser, dbSource); + break; + // Disable account + case 4: + UserAccount newDisableUser = new UserAccount(newCredentials.GetUserName(), + newCredentials.GetPassword(), DateTime.UtcNow); + accountService.DisableUser(newDisableUser, dbSource); + break; + // Enable account + case 5: + UserAccount newEnableUser = new UserAccount(newCredentials.GetUserName(), + newCredentials.GetPassword(), DateTime.UtcNow); + accountService.EnableUser(newEnableUser, dbSource); + break; + // View logs + case 6: + break; + // View archive + case 7: + break; + default: + Console.WriteLine("Invalid input.\nPlease enter a valid option.\n"); + break; } - else - { - - }*/ - /*conPsswrd = false; - } - else - { - Console.WriteLine("Passwords did not match, please try again."); - } -} -return true; -}*/ - - public void AccountController() - { - // Create objects - //UserAccount user = new UserAccount(); - UiPrint ui = new UiPrint(); - - bool foo = true; - - while (foo == true) - { - // sub menu - ui.SystemAccountMenu(); - // - + } + + string dbAction = user.username; + return dbAction; } - - } - + } } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/TeamHobby.HobbyProjectGenerator.UserManagement.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/TeamHobby.HobbyProjectGenerator.UserManagement.csproj index 9299c5f..be6931d 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/TeamHobby.HobbyProjectGenerator.UserManagement.csproj +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/TeamHobby.HobbyProjectGenerator.UserManagement.csproj @@ -7,7 +7,7 @@ - + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs index f4d4a8f..4b9a38f 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs @@ -6,37 +6,70 @@ using System.Threading.Tasks; namespace TeamHobby.HobbyProjectGenerator.UserManagement { + public class GetCredentials + { + public string? GetUserName() + { + Console.WriteLine("Please enter a username:"); + string? userName = Console.ReadLine(); + return userName; + } + public string? GetPassword() + { + Console.WriteLine("Please enter a password:"); + string? userPassword = Console.ReadLine(); + return userPassword; + } + /*public string ConfirmPassword() + { + Console.WriteLine(); + string confirmPassword = newUser.NewPassword; + }*/ + public string GetEmail() + { + Console.WriteLine("Please enter an email:"); + return Console.ReadLine(); + } + public string GetRole() + { + Console.WriteLine("Please enter the role of the user:"); + return Console.ReadLine(); + } + } public class UserAccount { // Admin Credentials - private string UserName; - private string Password; - private DateTime Time; + private string _userName; + private string _password; + private DateTime _Time; + // New User Credentials + private string _Email; + private string _Role; public UserAccount(string un, string pwd, DateTime TimeStamp) { - UserName = un; - Password = pwd; - Time = TimeStamp; + _userName = un; + _password = pwd; + _Time = TimeStamp; } - public string username { get { return UserName; } } - public string password { get { return Password; } } - - // New User Credentials - private string newusername; - private string newpassword; - private string newemail; - private DateTime newtime; - public void NewUser(string newUN, string newPWD, string Email, DateTime newTime) + public UserAccount(string newUN, string newPWD, string Email, string role, DateTime newTime) { - newusername = newUN; - newpassword = newPWD; - newemail = Email; - newtime = newTime; + _userName = newUN; + _password = newPWD; + _Role = role; + _Email = Email; + _Time = newTime; } - public string NewUserName { get { return newusername; } } - public string NewPassword { get { return newpassword; } } - public string NewEmail { get { return newemail; } } - public DateTime Newtime { get { return newtime; } } + public UserAccount() + { + _Role = "regular"; + _Time= DateTime.Now; + } + + public string username { get { return _userName; } } + public string password { get { return _password; } } + public string email { get { return _Email; } } + public string role { get { return _Role; } } + public DateTime Time { get { return _Time; } } } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/InMemoryUserService.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/InMemoryUserService.cs deleted file mode 100644 index 93fd0a5..0000000 --- a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/InMemoryUserService.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TeamHobby.HobbyProjectGenerator.Implementations -{ - public class InMemoryUserService - { - // Make it readonly so it can't be changed - private readonly IList _logstore; - - public InMemoryUserService() - { - _logstore = new List(); - } - - public IList GetAllUsers() - { - return _logstore; - } - - public bool User(string username) - { - try - { - //DateTime.UtcNow.ToString() + "->" + username; old way of doing it - _logstore.Add($"{DateTime.UtcNow}->{username}"); // New way of doing it - return true; - } - catch - { - return false; - } - } - /* - public bool User(DateTime timestamp, string username) - { - try - { - //DateTime.UtcNow.ToString() + "->" + username; old way of doing it - _logstore.Add($"{timestamp.ToUniversalTime()}->{username}"); // New way of doing it - return true; - } - catch - { - return false; - } - } - */ - } -} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/UiPrint.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/UiPrint.cs index d4e3cc5..411358d 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/UiPrint.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/UiPrint.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using TeamHobby.HobbyProjectGenerator.UserManagement; // Print Statements used throughout the program. @@ -21,12 +22,16 @@ namespace TeamHobby.HobbyProjectGenerator } public void SystemAccountMenu() { - // Create intial menu - Console.WriteLine("What would you like to do?"); - int num = 1; - Console.WriteLine(num + ".Create a new account."); - num += 1; - Console.WriteLine(num + ".Access Admin Features"); + UserAccount user = new UserAccount(); + // Menu for all UserManagement options + int menu = 0; + Console.WriteLine($"Welcome {user.username} to User Management.\n"); + Console.WriteLine("What would you like to do?\n"); + Console.WriteLine((menu + 1) + ". Create a new account."); + Console.WriteLine((menu + 1) + ". Edit an account."); + Console.WriteLine((menu + 1) + ". Delete an account."); + Console.WriteLine((menu + 1) + ". Disable an account."); + Console.WriteLine((menu + 1) + ". Enable an account."); } } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Authentication.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Authentication.cs deleted file mode 100644 index d123ab6..0000000 --- a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Authentication.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace TeamHobby.HobbyProjectGenerator -{ - public class User_Authentication - { - public IList GetAllUsers() - { - throw new NotImplementedException(); - } - - public bool User(string username) - { - //Console.WriteLine("Hello World!"); - //Console.WriteLine("Testing console"); - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Manager.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Manager.cs deleted file mode 100644 index c4c5619..0000000 --- a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Manager.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TeamHobby.HobbyProjectGenerator.Implementations -{ - public class User_Manager - { - public IList GetAllUsers() - { - throw new NotImplementedException(); - } - - public bool User(string username) - { - throw new NotImplementedException(); - } - } -} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln index 588b307..bf07f2e 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31919.166 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator", "TeamHobby.HobbyProjectGenerator.csproj", "{C75B6909-FD9E-4382-94B6-7CA2CE371C9A}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.UserManagement.Tests", "..\TeamHobby.UserManagement.Tests\TeamHobby.UserManagement.Tests.csproj", "{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Models", "..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj", "{75DED6C2-D404-4E71-A58B-0F616DB5C062}" @@ -22,6 +20,7 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.UserManagement", "..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj", "{2E7193B8-86B6-48DA-9671-CD84615A5F5D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Logging.Tests", "..\TeamHobby.HobbyProjectGenerator.Logging.Tests\TeamHobby.HobbyProjectGenerator.Logging.Tests.csproj", "{CA8D11CF-807C-4C90-A529-0371F73518F6}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.ArchiveTests", "..\TeamHobby.HobbyProjectGenerator.ArchiveTests\TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj", "{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Source Code/TeamHobby.UserManagement.Tests/TeamHobby.UserManagement.Tests.csproj b/Source Code/TeamHobby.UserManagement.Tests/TeamHobby.UserManagement.Tests.csproj index ec4c663..f72bee8 100644 --- a/Source Code/TeamHobby.UserManagement.Tests/TeamHobby.UserManagement.Tests.csproj +++ b/Source Code/TeamHobby.UserManagement.Tests/TeamHobby.UserManagement.Tests.csproj @@ -14,8 +14,4 @@ - - - - diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index 557eb25..057d4a5 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -4,6 +4,7 @@ using TeamHobby.HobbyProjectGenerator.Archive; using TeamHobby.HobbyProjectGenerator.DataAccess; using TeamHobby.HobbyProjectGenerator.Logging; using TeamHobby.HobbyProjectGenerator.UserManagement; + namespace TeamHobby.HobbyProjectGenerator.Main { @@ -22,13 +23,23 @@ namespace TeamHobby.HobbyProjectGenerator.Main "a password:"); string? userPassword = Console.ReadLine(); return userPassword; - } public class Controller { public static void Main(string[] args) { + // Console customization + // Change the look of the console + Console.Title = "HobbyProjectGenerator"; + // Change console text color + Console.ForegroundColor = ConsoleColor.Green; + // Change terminal height + Console.WindowHeight = 40; + + Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")); + + // Creating the Factory class // Logger log = new Logger(); //Logger.PrintTest(); //GetCredentials credentials = new GetCredentials(); @@ -47,22 +58,23 @@ namespace TeamHobby.HobbyProjectGenerator.Main // Creating the Factory class string dbType = "sql"; - RDSFactory factory = new RDSFactory(); + RDSFactory dbFactory = new RDSFactory(); // Testing Data Access Layer string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + - "TCPIP=1;" + - "SERVER=localhost;" + - "DATABASE=hobby;" + - "UID=root;" + - "PASSWORD=Teamhobby;" + - "PORT=3306;" + - "OPTION=3"; - // IDataSource datasource = factory.getDataSource(dbType, dbInfo); - - + "TCPIP=1;" + + "SERVER=localhost;" + + "DATABASE=hobby;" + + "UID=root;" + + "PASSWORD=Teamhobby;" + + "OPTION=3"; IDataSource datasource = factory.getDataSource(dbType, dbInfo); + "PORT=3306;"; + + "OPTION=3"; + + IDataSource datasource = dbFactory.getDataSource(dbType, dbInfo); // Create manager class from UserManagement SystemAccountManager manager = new SystemAccountManager(); @@ -77,11 +89,11 @@ namespace TeamHobby.HobbyProjectGenerator.Main // Create UserAccount class UserAccount user = new UserAccount(username, password, TimeStamp); - manager.CreateUserRecord(user); - + Console.Write(manager.CreateUserRecord(user, datasource)); + //Console.WriteLine(value: $"Welcome {username}\n"); - /* string sqlQuery = "Select * from log;"; + /* string sqlQuery = "Select * from log;"; Object result = datasource.ReadData(sqlQuery); Console.WriteLine("type of Result: " + result.GetType()); OdbcDataReader reader = null; @@ -103,18 +115,19 @@ namespace TeamHobby.HobbyProjectGenerator.Main // Closing the connection sqlDS.getConnection().Close();*/ - // While loop to keep this running forever with UserManagement - // Testing archive Manager - //while (true) - //{ - /* string currentDate = DateTime.Now.ToString("dd"); - string currentTime = DateTime.Now.ToString("T"); - Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime); - if (String.Equals(currentDate, "1") && String.Equals(currentTime, "00:00:00 AM")){ - ArchiveManager archive = new ArchiveManager(datasource); - archive.Controller(); - }*/ - //} + /* // While loop to keep this running forever with UserManagement + // Testing archive Manager + //while (true) + //{ + string currentDate = DateTime.Now.ToString("dd"); + string currentTime = DateTime.Now.ToString("T"); + Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime); + if (String.Equals(currentDate, "1") && String.Equals(currentTime, "00:00:00 AM")) + { + ArchiveManager archive = new ArchiveManager(datasource); + archive.Controller(); + } + //}*/ @@ -146,7 +159,7 @@ namespace TeamHobby.HobbyProjectGenerator.Main //// Remove entries fromt the database //sqlDS.RemoveEntries(); - + // 2.Inserting Data into the database: @@ -163,80 +176,80 @@ namespace TeamHobby.HobbyProjectGenerator.Main //datasource.WriteData(sqlRemove); //Console.WriteLine("Writing completed. "); - /* bool MainMenu = true; + /* bool MainMenu = true; - // Set up menu loop - while (MainMenu == true) - { - // Console customization - // Change the look of the console - Console.Title = "HobbyProjectGenerator"; - // Change console text color - Console.ForegroundColor = ConsoleColor.Green; - // Change terminal height - Console.WindowHeight = 40; + // Set up menu loop + while (MainMenu == true) + { + // Console customization + // Change the look of the console + Console.Title = "HobbyProjectGenerator"; + // Change console text color + Console.ForegroundColor = ConsoleColor.Green; + // Change terminal height + Console.WindowHeight = 40; - // Create class objects - UiPrint menu = new UiPrint(); + // Create class objects + UiPrint menu = new UiPrint(); - // Print main menu - menu.InitialMenu(); + // Print main menu + menu.InitialMenu(); - // Set up try-catch for invalid inputs - try - { - // Get user choice - string initialChoice = Console.ReadLine(); - // Convert to integer - int Choice = Convert.ToInt32(initialChoice); + // Set up try-catch for invalid inputs + try + { + // Get user choice + string initialChoice = Console.ReadLine(); + // Convert to integer + int Choice = Convert.ToInt32(initialChoice); - switch (Choice) - { - case 0: - MainMenu = false; - break; - // Create a new account - case 1: + switch (Choice) + { + case 0: + MainMenu = false; + break; + // Create a new account + case 1: user.newUser(); - break; - // Access Admin features - case 2: - // Ask for Admin login credentials - Console.WriteLine("Please enter a username:"); - string AdminUser = Console.ReadLine(); - Console.WriteLine("Please enter the password for" + AdminUser); - string AdminPsswrd = Console.ReadLine(); + break; + // Access Admin features + case 2: + // Ask for Admin login credentials + Console.WriteLine("Please enter a username:"); + string AdminUser = Console.ReadLine(); + Console.WriteLine("Please enter the password for" + AdminUser); + string AdminPsswrd = Console.ReadLine(); - // Check if the username and password match a record within the administrators + // Check if the username and password match a record within the administrators - // Show new administrator menu - int AdminNum = 0; - Console.WriteLine("Welcome" + AdminUser); - Console.WriteLine("What would you like to do?"); - Console.WriteLine("1.View normal user records."); - Console.WriteLine("2.View Administrator user records."); - Console.WriteLine("3.View log files."); - Console.WriteLine(""); - Console.WriteLine(""); - Console.WriteLine(""); - Console.WriteLine(""); - Console.WriteLine(""); + // Show new administrator menu + int AdminNum = 0; + Console.WriteLine("Welcome" + AdminUser); + Console.WriteLine("What would you like to do?"); + Console.WriteLine("1.View normal user records."); + Console.WriteLine("2.View Administrator user records."); + Console.WriteLine("3.View log files."); + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); - break; - default: - Console.WriteLine("Invalid choice, please enter a valid number."); - break; - }; - } - // Catch invalid keys such as spamming enter - catch - { - MainMenu = false; - };*/ + break; + default: + Console.WriteLine("Invalid choice, please enter a valid number."); + break; + }; + } + // Catch invalid keys such as spamming enter + catch + { + MainMenu = false; + };*/ //} } diff --git a/Source Code/main/main.csproj b/Source Code/main/main.csproj index 6444b61..5dde81b 100644 --- a/Source Code/main/main.csproj +++ b/Source Code/main/main.csproj @@ -19,7 +19,6 @@ - diff --git a/doc/LowLevel/ArchivingWithError.png b/doc/LowLevel/ArchivingLL/ArchivingWithError.png similarity index 100% rename from doc/LowLevel/ArchivingWithError.png rename to doc/LowLevel/ArchivingLL/ArchivingWithError.png diff --git a/doc/LowLevel/ArchivingWithError.svg b/doc/LowLevel/ArchivingLL/ArchivingWithError.svg similarity index 100% rename from doc/LowLevel/ArchivingWithError.svg rename to doc/LowLevel/ArchivingLL/ArchivingWithError.svg diff --git a/doc/LowLevel/ArchivingWithError.txt b/doc/LowLevel/ArchivingLL/ArchivingWithError.txt similarity index 100% rename from doc/LowLevel/ArchivingWithError.txt rename to doc/LowLevel/ArchivingLL/ArchivingWithError.txt diff --git a/doc/LowLevel/ArchivingWithSingleton.pdf b/doc/LowLevel/ArchivingLL/ArchivingWithSingleton.pdf similarity index 100% rename from doc/LowLevel/ArchivingWithSingleton.pdf rename to doc/LowLevel/ArchivingLL/ArchivingWithSingleton.pdf diff --git a/doc/LowLevel/ArchvingMasterCon.txt b/doc/LowLevel/ArchivingLL/ArchvingMasterCon.txt similarity index 100% rename from doc/LowLevel/ArchvingMasterCon.txt rename to doc/LowLevel/ArchivingLL/ArchvingMasterCon.txt diff --git a/doc/LowLevel/archiving.pdf b/doc/LowLevel/ArchivingLL/archiving.pdf similarity index 100% rename from doc/LowLevel/archiving.pdf rename to doc/LowLevel/ArchivingLL/archiving.pdf diff --git a/doc/LowLevel/archiving.txt b/doc/LowLevel/ArchivingLL/archiving.txt similarity index 100% rename from doc/LowLevel/archiving.txt rename to doc/LowLevel/ArchivingLL/archiving.txt diff --git a/doc/LowLevel/archiving2.png b/doc/LowLevel/ArchivingLL/archiving2.png similarity index 100% rename from doc/LowLevel/archiving2.png rename to doc/LowLevel/ArchivingLL/archiving2.png diff --git a/doc/LowLevel/archiving2.txt b/doc/LowLevel/ArchivingLL/archiving2.txt similarity index 100% rename from doc/LowLevel/archiving2.txt rename to doc/LowLevel/ArchivingLL/archiving2.txt diff --git a/doc/LowLevel/archivingMasterCon.pdf b/doc/LowLevel/ArchivingLL/archivingMasterCon.pdf similarity index 100% rename from doc/LowLevel/archivingMasterCon.pdf rename to doc/LowLevel/ArchivingLL/archivingMasterCon.pdf diff --git a/doc/LowLevel/archivingSubmission.pdf b/doc/LowLevel/ArchivingLL/archivingSubmission.pdf similarity index 100% rename from doc/LowLevel/archivingSubmission.pdf rename to doc/LowLevel/ArchivingLL/archivingSubmission.pdf diff --git a/doc/LowLevel/archivingWithError.pdf b/doc/LowLevel/ArchivingLL/archivingWithError.pdf similarity index 100% rename from doc/LowLevel/archivingWithError.pdf rename to doc/LowLevel/ArchivingLL/archivingWithError.pdf diff --git a/doc/LowLevel/archivingWithError2.pdf b/doc/LowLevel/ArchivingLL/archivingWithError2.pdf similarity index 100% rename from doc/LowLevel/archivingWithError2.pdf rename to doc/LowLevel/ArchivingLL/archivingWithError2.pdf diff --git a/doc/LowLevel/archiving_5.txt b/doc/LowLevel/ArchivingLL/archiving_5.txt similarity index 100% rename from doc/LowLevel/archiving_5.txt rename to doc/LowLevel/ArchivingLL/archiving_5.txt diff --git a/doc/LowLevel/archivngWithError.txt b/doc/LowLevel/ArchivingLL/archivngWithError.txt similarity index 100% rename from doc/LowLevel/archivngWithError.txt rename to doc/LowLevel/ArchivingLL/archivngWithError.txt diff --git a/doc/LowLevel/arcvhingMasterCon.pdf b/doc/LowLevel/ArchivingLL/arcvhingMasterCon.pdf similarity index 100% rename from doc/LowLevel/arcvhingMasterCon.pdf rename to doc/LowLevel/ArchivingLL/arcvhingMasterCon.pdf diff --git a/src/dbCode/UserManagementDDL.txt b/src/dbCode/UserManagementDDL.txt new file mode 100644 index 0000000..a4022e6 --- /dev/null +++ b/src/dbCode/UserManagementDDL.txt @@ -0,0 +1,38 @@ +create table users +( + UserName varchar(50) charset utf8mb3 not null + primary key, + Password varchar(50) charset utf8mb3 null, + Role varchar(50) not null, + IsActive int default 1 null, + CreatedBy varchar(50) charset utf8mb3 null, + CreatedDate datetime null, + Email varchar(50) null, + constraint users_Email_uindex + unique (Email), + constraint users_UserName_uindex + unique (UserName), + constraint users_roles_Role_fk + foreign key (Role) references roles (Role) +); + +INSERT INTO hobby.users (UserName, Password, Role, IsActive, CreatedBy, CreatedDate, Email) VALUES +('Colin ', 'Waffle', 'Admin', 1, 'Jacob', '2021-12-13 04:27:42', null), +('Danny', 'Spartan', 'Admin', 1, 'Jacob', '2021-12-13 04:29:54', null), +('Jacob', 'Teamhobby1234', 'Admin', 1, 'SystemCreator', '2021-12-13 03:25:14', null), +('Long', 'Joystick', 'regular', 1, 'Jacob', '2021-12-13 04:29:57', null), +('Rifat', 'ApproveDar', 'Admin', 1, 'Jacob', '2021-12-13 04:29:55', null); + + +create table roles +( + RoleID int not null, + Role varchar(50) charset utf8mb3 not null, + CreatedBy varchar(200) charset utf8mb3 not null, + CreatedDate datetime not null, + constraint role_pk + primary key (Role) +); + +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('Admin', 'Jacob', '2021-12-13 03:25:14'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Colin', '2021-12-13 03:25:14'); diff --git a/src/dbCode/fullDDL.txt b/src/dbCode/fullDDL.txt new file mode 100644 index 0000000..f77d833 --- /dev/null +++ b/src/dbCode/fullDDL.txt @@ -0,0 +1,152 @@ +create database Hobby; + +use hobby; + +create table users +( + UserName varchar(50) charset utf8mb3 not null + primary key, + Password varchar(50) charset utf8mb3 null, + RoleID int auto_increment, + IsActive int default 1 null, + CreatedBy varchar(50) charset utf8mb3 null, + CreatedDate datetime null, + constraint users_UserName_uindex + unique (UserName), + constraint users_roles_RoleID_fk + foreign key (RoleID) references roles (RoleID) +); + +INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Colin ', 'Waffle', 'Jacob', '2021-12-13 04:27:42'); +INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Danny', 'Spartan', 'Jacob', '2021-12-13 04:29:54'); +INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Jacob', 'Teamhobby1234', 'SystemCreator', '2021-12-13 03:25:14'); +INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Long', 'Joystick', 'Jacob', '2021-12-13 04:29:57'); +INSERT INTO hobby.users (UserName, Password, CreatedBy, CreatedDate) VALUES ('Rifat', 'ApproveDar', 'Jacob', '2021-12-13 04:29:55'); + + +create table roles +( + RoleID int auto_increment + primary key, + Role varchar(50) charset utf8mb3 null, + CreatedBy varchar(200) charset utf8mb3 null, + CreatedDate datetime null +); + +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('Admin', 'SystemCreator', '2021-12-13 03:25:14'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Colin', '2021-12-13 03:25:14'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Colin', '2021-12-13 03:25:14'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:44'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:46'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:47'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:47'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:49'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:50'); +INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES ('regular', 'Jacob', '2021-12-13 03:37:51'); + + +alter table users + add constraint users_roles_RoleID_fk + foreign key (RoleID) references roles (RoleID); + +SET Global innodb_file_per_table=ON; +-- SET GLOBAL innodb_file_format='Barracuda'; + +SET GLOBAL innodb_default_row_format='dynamic'; + +SET GLOBAL innodb_compression_algorithm='zlib'; + +-- Check for system settings +SHOW VARIABLES LIKE 'innodb_compression_algorithm'; +SHOW VARIABLES LIKE 'innodb_default_row_format'; +SHOW VARIABLES LIKE '%innodb%'; + +CREATE TABLE Persons ( + PersonID int, + LastName varchar(255), + FirstName varchar(255), + Address varchar(255), + City varchar(255) +); + +CREATE DATABASE testDB; + +-- Hobby DDL +-- Log level table +create table LogLevel +( + LvName varchar(50) not null, + LvComment varchar(500) not null, + constraint LogLevel_pk + primary key (LvName) +); + +-- Log categories table +create table LogCategories +( + catName varchar(50) not null, + catComment varchar(255) not null, + constraint LogCategories_pk primary key (catName) +); + +-- DDL for log table +create table Log +( + LtimeStamp datetime default CURRENT_TIMESTAMP null, + logID int auto_increment not null, + LvName varchar(50) not null, + catName varchar(50) not null, + userOP varchar(50) not null, + logMessage varchar(255) not null, + + constraint LogLvName_fk foreign key (LvName) references loglevel (LvName), + constraint LogCatName_fk foreign key (catName) references logcategories (catName), + constraint Log_pk primary key (logID) + +); + +create table Archive +( + LtimeStamp datetime null, + logID int not null, + LvName varchar(50) not null, + catName varchar(50) not null, + userOP varchar(50) not null, + logMessage varchar(255) not null, + + constraint Archive_pk primary key (logID) +) + ENGINE=InnoDB + PAGE_COMPRESSED=1 + PAGE_COMPRESSION_LEVEL=9; + +drop table archive; + +-- Dummy data for testing purposes +-- Log categories data +INSERT into logcategories(catName, catComment) values + ('View', 'view layer'), + ('Business', 'business layer'), + ('Server', 'server layer'), + ('Data', 'data layer'); + +-- Log level data +INSERT into loglevel(lvname, lvcomment) values + ('Info', 'some sys flow'), + ('Debug', 'info for fixing bugs'), + ('Warning', 'track system failure'), + ('Error', 'some sys errors'); + +-- Log table data +INSERT into log(lvname, catname, userop, logmessage) values + ('Info', 'View', 'create some projects', 'new account created'), + ('Info', 'Business', 'create some projects', 'new projects made'), + ('Info', 'View', 'log out', 'log out successful'), + ('Info', 'Business', 'log in', 'log in successfully'), + ('Info', 'View', 'search for projects', 'result return'); + +select * from logcategories; +select * from log; + + +