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/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj index 09da541..65fcde5 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj @@ -4,6 +4,7 @@ net6.0 enable enable + AnyCPU;x86 diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs index 7da2223..9775996 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data.Odbc; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -197,6 +198,98 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests } + public void RemoveEntriesTest(IDataSource sqlDAO) + { + Console.WriteLine("TESTING - REMOVE ENTRIES"); + + // Arrange + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + SqlDAO sqlDS = null; + + if (sqlDAO.GetType() == typeof(SqlDAO)) + { + sqlDS = (SqlDAO)sqlDAO; + //sqlDS.GetConnection().Open(); + + // Act + Console.WriteLine("\nInserting into archive..."); + sqlDS.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values " + + "('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," + + "('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," + + "('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," + + "('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," + + "('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return')," + + "('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully');"); + + OdbcDataReader odbcObj = (OdbcDataReader)sqlDS.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;"); + + int count = 0; + while (odbcObj.Read()) { ++count; } + Console.WriteLine("Number of entries > 30 days old: " + count); + + Console.WriteLine("\nRemoving entries from archive..."); + sqlDS.RemoveEntries(); + + odbcObj = (OdbcDataReader)sqlDS.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;"); + + count = 0; + while (odbcObj.Read()) { ++count; } + Console.WriteLine("Number of entries > 30 days old: " + count); + + // Assert + bool expectedVal = true; + bool actualVal = !Convert.ToBoolean(count); + + if (expectedVal == actualVal) + { + Console.WriteLine("\nExpected: {0}, Actual: {0}. Entries removed correctly.", expectedVal, actualVal); + } + else + { + Console.WriteLine("\nExpected: {0}, Actual: {1}. Entries not removed.", expectedVal, actualVal); + } + + //sqlDS.GetConnection().Close(); + } + + return; + } + + public void RemoveOutputFileTest(IDataSource sqlDAO) + { + Console.WriteLine("TESTING - REMOVE OUTPUT FILE\n"); + + // Arrange + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + SqlDAO sqlDS = null; + + if (sqlDAO.GetType() == typeof(SqlDAO)) + { + sqlDS = (SqlDAO)sqlDAO; + } + + // Act + string filepath = archiveManager.CreateOutFileName(); + Console.WriteLine("\nRemoving file..."); + sqlDS.RemoveOutputFile(filepath); + + // Assert + bool expectedVal = false; + bool actualVal = File.Exists(filepath); + Console.WriteLine("Checking if file exists: " + actualVal); + + if (expectedVal == actualVal) + { + Console.WriteLine("\nExpected: {0}, Actual: {0}. Output file removed correctly.", expectedVal, actualVal); + } + else + { + Console.WriteLine("\nExpected: {0}, Actual: {1}. Output file NOT removed.", expectedVal, actualVal); + } + + return; + } + public static void Main(string[] args) { string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + @@ -206,6 +299,7 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests "PASSWORD=Teamhobby;" + "OPTION=3"; SqlDAO sqlDAO = new SqlDAO(dbInfo); + sqlDAO.GetConnection().Open(); //ArchiveManager archiveManager = new ArchiveManager(sqlDAO); // Testing folder creation @@ -226,12 +320,21 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests Console.WriteLine(""); - // Testing clean up sequence //test.IsCleaningUpCompleted(sqlDAO); //Console.WriteLine("-----------------"); //Console.WriteLine(""); + // Testing remove entries + test.RemoveEntriesTest(sqlDAO); + Console.WriteLine("-----------------"); + Console.WriteLine(""); + + // Testing remove output file + test.RemoveOutputFileTest(sqlDAO); + Console.WriteLine("-----------------"); + Console.WriteLine(""); + sqlDAO.GetConnection().Close(); } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 5cf2f70..56c42f7 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; @@ -42,7 +42,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - _conn.Open(); + //_conn.Open(); OdbcCommand command = new OdbcCommand(cmd, _conn); OdbcDataReader reader = command.ExecuteReader(); @@ -67,12 +67,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - _conn.Open(); - + //_conn.Open(); + OdbcCommand command = new OdbcCommand(cmd, _conn); command.ExecuteNonQuery(); - - _conn.Close(); + + //_conn.Close(); return true; } @@ -84,7 +84,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } finally { - _conn.Close(); + //_conn.Close(); } } @@ -94,12 +94,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - _conn.Open(); + //_conn.Open(); OdbcCommand command = new OdbcCommand(cmd, _conn); command.ExecuteNonQuery(); - _conn.Close(); + //_conn.Close(); return true; } @@ -111,7 +111,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } finally { - _conn.Close(); + //_conn.Close(); } } @@ -120,12 +120,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - _conn.Open(); + //_conn.Open(); OdbcCommand command = new OdbcCommand(cmd, _conn); command.ExecuteNonQuery(); - _conn.Close(); + //_conn.Close(); return true; } @@ -137,7 +137,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } finally { - _conn.Close(); + //_conn.Close(); } } @@ -177,7 +177,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess public bool CopyToFile(string filePath){ try { - _conn.Open(); + //_conn.Open(); // Conver backward slash in to forward slash filePath = filePath.Replace("\\", "/"); string sqlQuery = "SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' " + @@ -200,19 +200,19 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess Console.WriteLine("Output to a file completed. "); - _conn.Close(); + //_conn.Close(); return true; } catch (Exception ex) { - _conn.Close(); + //_conn.Close(); Console.WriteLine("Error when copying query to a file !!, will be handled higher up the call stack"); throw; } finally { - _conn.Close(); + //_conn.Close(); } } 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.Logging/Contracts/ILogger.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Contracts/ILogger.cs new file mode 100644 index 0000000..9aee5ba --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Contracts/ILogger.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Logging +{ + public interface ILogger + { + bool Log(LogEntry log); + + // IList GetAllLogs(); + + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Contracts/ILoggerFactory.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Contracts/ILoggerFactory.cs new file mode 100644 index 0000000..cf0d199 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Contracts/ILoggerFactory.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Logging.Contracts +{ + public interface ILoggerFactory + { + ILogger CreateLogger() + { + return new DBLogger(); + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/ConsoleLogger.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/ConsoleLogger.cs new file mode 100644 index 0000000..ba0c24d --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/ConsoleLogger.cs @@ -0,0 +1,16 @@ +// using System; +// using System.Collections.Generic; +// using System.Linq; +// using System.Text; +// using System.Threading.Tasks; + +// namespace TeamHobby.HobbyProjectGenerator.Logging +// { +// public class ConsoleLogger : ILogger +// { +// public bool Log(LogEntry log) +// { +// return true; +// } +// } +// } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLogger.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLogger.cs new file mode 100644 index 0000000..132ee82 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLogger.cs @@ -0,0 +1,24 @@ +using System; + +namespace TeamHobby.HobbyProjectGenerator.Logging +{ + public class DBLogger : ILogger + { + public DBLogger() + { + } + + public IList GetAllLogs() + { + throw new NotImplementedException(); + } + + public bool Log(LogEntry log) + { + throw new NotImplementedException(); + } + + + } + +} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLoggerFactory.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLoggerFactory.cs new file mode 100644 index 0000000..f790cbb --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/DBLoggerFactory.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeamHobby.HobbyProjectGenerator.Logging.Contracts; + +namespace TeamHobby.HobbyProjectGenerator.Logging.Implementations +{ + public class DBLoggerFactory : ILoggerFactory + { + public DBLoggerFactory() + { + } + public ILogger CreateLogger() + { + return new DBLogger(); + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/FileLogger.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/FileLogger.cs new file mode 100644 index 0000000..522f7ab --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/FileLogger.cs @@ -0,0 +1,23 @@ +// using System; + +// namespace TeamHobby.HobbyProjectGenerator.Logging +// { +// public class FileLogger : Ilogger +// { +// public FileLogger() +// { +// } + +// public IList GetAllLogs() +// { +// throw new NotImplementedException(); +// } + +// public bool Log(LogEntry log) +// { +// throw new NotImplementedException(); +// } + +// } + +// } \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/InMemoryLogger.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/InMemoryLogger.cs new file mode 100644 index 0000000..233e083 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/Implementations/InMemoryLogger.cs @@ -0,0 +1,58 @@ +// using System; +// using System.Collections.Generic; +// namespace TeamHobby.HobbyProjectGenerator.Logging +// { +// // implementation of ILogger that stores logs as they initialize +// public class InMemoryLogger : ILogger +// { +// // make readonly to prevent it from being changed somewhere other than in the constructor +// private readonly IList _logStore; + +// public InMemoryLogger() +// { +// // list of current logs +// _logStore = new List(); +// } + +// public InMemoryLogger(IList logStore) +// { +// _logStore = logStore; +// } + +// public bool Log(LogEntry entry) +// { +// if (entry is null) +// { +// throw new ArgumentNullException(nameof(entry)); +// } + +// try +// { +// // string interpolation to add UTC timestamp to log description +// //_logStore.Add($"{DateTime.UtcNow}-> {description}"); +// return true; +// } +// catch +// { +// return false; +// } +// } +// public IList GetAllLogs() +// { +// return _logStore; +// } + + +// public override bool Equals(object? obj) +// { +// return obj is InMemoryLogger logger && +// EqualityComparer>.Default.Equals(_logStore, logger._logStore); +// } + +// public override int GetHashCode() +// { +// return HashCode.Combine(_logStore); +// } +// } + +// } \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LogEntry.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LogEntry.cs new file mode 100644 index 0000000..af049d1 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LogEntry.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Logging +{ + public enum LogLevel + { + Info, Debug, Warning, Error + } + + public enum LogCategory + { + View, Business, Server, Data, Datastore + } + + // LogEntry is a record type with init properties for each field + // ensures that log entries are immutable after initialization + public record LogEntry + { + public LogLevel level { get; init; } + public LogCategory category { get; init; } + public string user { get; init; } + public string description { get; init; } + public DateTime timestamp { get; init; } + + + // Constructor requireing only the description as an arg + // Assigns default values for LogLevel (Info), LogCategory (Server), user ("System"), and the UTC time at initialization for timestamp + public LogEntry(string description) + { + this.level = LogLevel.Info; + this.category = LogCategory.Server; + this.user = "System"; + this.description = description; + this.timestamp = DateTime.UtcNow; + } + // Constructor with args for all fields except timestamp + // timestamp is always set to the UTC time at the time of initialization + public LogEntry(LogLevel level, string user, LogCategory category, string description) + { + this.level = level; + this.category = category; + this.user = user; + this.description = description; + this.timestamp = DateTime.UtcNow; + } + + + } +} + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LoggingManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LoggingManager.cs new file mode 100644 index 0000000..ca367fe --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/LoggingManager.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeamHobby.HobbyProjectGenerator.DataAccess; +using TeamHobby.HobbyProjectGenerator.Logging.Contracts; +using TeamHobby.HobbyProjectGenerator.Logging.Implementations; + +namespace TeamHobby.HobbyProjectGenerator.Logging +{ + internal class LoggingManager + { + private readonly IDataSource _conn; + private readonly ILogger _logger; + private readonly ILoggerFactory _factory; + private readonly LogEntry _logEntry; + + // Both Constructors take an IDataSource arg to make logging extensible to future data sources + // first constructor has no additional args - defaults to using the DBFactiry implementation + public LoggingManager(IDataSource dataSource) + { + _conn = dataSource; + _factory = new DBLoggerFactory(); + _logger = _factory.CreateLogger(); + } + // second constructor takes an additional ILoggerFactory arg - allows for extensible logger types + public LoggingManager(IDataSource dataSource, ILoggerFactory factory) + { + _conn = dataSource; + _factory = factory; + _logger = _factory.CreateLogger(); + + } + + public void Process() + { + _logger.Log(_logEntry); + } + + + + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby - Backup.HobbyProjectGenerator.Logging.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby - Backup.HobbyProjectGenerator.Logging.csproj new file mode 100644 index 0000000..97db0f1 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby - Backup.HobbyProjectGenerator.Logging.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + Library + AnyCPU + AnyCPU;x86 + + + + True + + + + True + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby.HobbyProjectGenerator.Logging.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby.HobbyProjectGenerator.Logging.csproj new file mode 100644 index 0000000..c9596e5 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Logging/TeamHobby.HobbyProjectGenerator.Logging.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + enable + enable + AnyCPU;x86 + + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs new file mode 100644 index 0000000..198f16c --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs @@ -0,0 +1,81 @@ +using System; +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 +{ + 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 new file mode 100644 index 0000000..28d621e --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs @@ -0,0 +1,270 @@ +using System; +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.DataAccess; + +namespace TeamHobby.HobbyProjectGenerator.UserManagement +{ + public class SystemAccountManager + { + 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=='@' + || un == '.' || un == ',' || un == '!'); + + 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) + { + 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 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) + { + 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"; + } + else + { + return "Invalid input\n"; + } + } + public string IsInputValid(string checkUN, string checkPWD, string email, string role) + { + // 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)); + + // Check if any are empty + if (checkUN == null || checkPWD == null || email == null) + { + 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; + + if (confirmAdmin.GetType() == typeof(OdbcDataReader)) + { + reader = (OdbcDataReader)confirmAdmin; + } + + // 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) + { + // 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; + } + } + + 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 new file mode 100644 index 0000000..be6931d --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/TeamHobby.HobbyProjectGenerator.UserManagement.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs new file mode 100644 index 0000000..4b9a38f --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +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; + // New User Credentials + private string _Email; + private string _Role; + + public UserAccount(string un, string pwd, DateTime TimeStamp) + { + _userName = un; + _password = pwd; + _Time = TimeStamp; + } + public UserAccount(string newUN, string newPWD, string Email, string role, DateTime newTime) + { + _userName = newUN; + _password = newPWD; + _Role = role; + _Email = Email; + _Time = 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/Contracts/IDataSource.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Contracts/IDataSource.cs deleted file mode 100644 index 7db156f..0000000 --- a/Source Code/TeamHobby.HobbyProjectGenerator/Contracts/IDataSource.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TeamHobby.HobbyProjectGenerator.Contracts -{ - internal interface IDataSource - { - } -} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Contracts/IUserService.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Contracts/IUserService.cs deleted file mode 100644 index 96fff23..0000000 --- a/Source Code/TeamHobby.HobbyProjectGenerator/Contracts/IUserService.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TeamHobby.HobbyProjectGenerator -{ - public interface IUserService - { - // Public methods shouldn't be void so it can be tested - bool User(string username); - IList GetAllUsers(); - } -} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/Database_Users.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/Database_Users.cs deleted file mode 100644 index 29bf72b..0000000 --- a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/Database_Users.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 -{ - internal class Database_Users : IUserService - { - public IList GetAllUsers() - { - throw new NotImplementedException(); - } - - public bool User(string username) - { - throw new NotImplementedException(); - } - } -} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/InMemoryUserService.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/InMemoryUserService.cs deleted file mode 100644 index 3b14f48..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 : IUserService - { - // 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 new file mode 100644 index 0000000..411358d --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/UiPrint.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeamHobby.HobbyProjectGenerator.UserManagement; + +// Print Statements used throughout the program. + +namespace TeamHobby.HobbyProjectGenerator +{ + 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 SystemAccountMenu() + { + 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 718f331..0000000 --- a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Authentication.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace TeamHobby.HobbyProjectGenerator -{ - public class User_Authentication : IUserService - { - 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 56b859f..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 : IUserService - { - public IList GetAllUsers() - { - throw new NotImplementedException(); - } - - public bool User(string username) - { - throw new NotImplementedException(); - } - } -} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.csproj b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.csproj index 132c02c..0a03a26 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.csproj +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln index ac07ef1..fc15a13 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}" @@ -17,6 +15,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.Main", "..\TeamHo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.DataAccess", "..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj", "{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Logging", "..\TeamHobby.HobbyProjectGenerator.Logging\TeamHobby.HobbyProjectGenerator.Logging.csproj", "{C0494115-838E-43A3-8896-133E5D1E874A}" +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}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.ArchiveTests", "..\TeamHobby.HobbyProjectGenerator.ArchiveTests\TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj", "{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}" EndProject Global @@ -25,13 +29,11 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|Any CPU.Build.0 = Release|Any CPU {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.ActiveCfg = Release|Any CPU {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.Build.0 = Release|Any CPU {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.Build.0 = Debug|Any CPU {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.ActiveCfg = Release|Any CPU {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.Build.0 = Release|Any CPU {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -43,13 +45,24 @@ Global {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.ActiveCfg = Release|Any CPU {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.Build.0 = Release|Any CPU {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.Build.0 = Debug|Any CPU {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.ActiveCfg = Release|Any CPU {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.Build.0 = Release|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.Build.0 = Debug|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.Build.0 = Release|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.Build.0 = Release|Any CPU + {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.Build.0 = Release|Any CPU + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.Build.0 = Release|Any CPU {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.Build.0 = Debug|Any CPU {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Source Code/TeamHobby.Main/HobbyMain.cs b/Source Code/TeamHobby.Main/HobbyMain.cs index c293745..58e9b09 100644 --- a/Source Code/TeamHobby.Main/HobbyMain.cs +++ b/Source Code/TeamHobby.Main/HobbyMain.cs @@ -128,7 +128,7 @@ public class HobbyMain Console.WriteLine("Read the database"); while (reader.Read()) { - Console.WriteLine("Date={0} {1} {2} {3} {4} {5}", reader[0], reader[1], reader[2], reader[3],reader[4], reader[5]); + Console.WriteLine("Date={0} {1} {2} {3} {4} {5}", reader[0], reader[1], reader[2], reader[3], reader[4], reader[5]); //Console.WriteLine("Col A: {0} ", reader[0]); //Console.WriteLine("Column: " + reader.FieldCount); //Console.WriteLine("Column={1}", reader[1]); diff --git a/Source Code/TeamHobby.Main/MasterController.cs b/Source Code/TeamHobby.Main/MasterController.cs index be53071..838f386 100644 --- a/Source Code/TeamHobby.Main/MasterController.cs +++ b/Source Code/TeamHobby.Main/MasterController.cs @@ -1,7 +1,9 @@ -public class MasterController{ - - public static void main(string[] args){ +public class MasterController +{ + + public static void main(string[] args) + { //The main Controller of the program, It will run all services here @@ -13,12 +15,14 @@ public class MasterController{ int userInput = 0; - while (userInput != -1) { + while (userInput != -1) + { // Print the menu // - if (userInput == 1){ + if (userInput == 1) + { // 1. User Managment goes here } 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 5f6c8b2..5ef6620 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -1,13 +1,16 @@ -using main; -using System; +using System; using System.Data.Odbc; using TeamHobby.HobbyProjectGenerator.Archive; using TeamHobby.HobbyProjectGenerator.DataAccess; +using TeamHobby.HobbyProjectGenerator.Logging; +using TeamHobby.HobbyProjectGenerator.UserManagement; namespace TeamHobby.HobbyProjectGenerator.Main { + public class GetCredentials { + public string? GetUserName() { Console.WriteLine("Please enter a username:"); @@ -16,37 +19,81 @@ namespace TeamHobby.HobbyProjectGenerator.Main } public string? GetPassword() { - Console.WriteLine("Please enter a password:"); + Console.WriteLine("Please enter " + + "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(); //string? username = credentials.GetUserName(); //string? password = credentials.GetPassword(); - - +// 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(value: $"username is {username}\npassword is {password}"); // Creating the Factory class + // Creating the Factory class + string dbType = "sql"; 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;" + "OPTION=3"; - IDataSource datasource = dbFactory.getDataSource(dbType,dbInfo); + IDataSource datasource = factory.getDataSource(dbType, dbInfo); + "PORT=3306;"; + - string sqlQuery = "Select * from log;"; + "OPTION=3"; + + IDataSource datasource = dbFactory.getDataSource(dbType, dbInfo); + // Create manager class from UserManagement + SystemAccountManager manager = new SystemAccountManager(); + + // Admin Sign in + GetCredentials credentials = new GetCredentials(); + string? username = credentials.GetUserName(); + string? password = credentials.GetPassword(); + + // Get time of login attempt + DateTime TimeStamp = DateTime.UtcNow; + + // Create UserAccount class + UserAccount user = new UserAccount(username, password, TimeStamp); + + Console.Write(manager.CreateUserRecord(user, datasource)); + + //Console.WriteLine(value: $"Welcome {username}\n"); + + /* string sqlQuery = "Select * from log;"; Object result = datasource.ReadData(sqlQuery); Console.WriteLine("type of Result: " + result.GetType()); OdbcDataReader reader = null; @@ -71,19 +118,19 @@ namespace TeamHobby.HobbyProjectGenerator.Main // 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"); - string activateDate = "01"; - string activateTime = "00:00:00 AM"; - Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime); - if (String.Equals(currentDate, activateDate) && String.Equals(currentTime, activateTime)) - { - ArchiveManager archive = new ArchiveManager(datasource); - archive.Controller(); - } - } + //while (true) + //{ + //string currentDate = DateTime.Now.ToString("dd"); + //string currentTime = DateTime.Now.ToString("T"); + //string activateDate = "01"; + //string activateTime = "00:00:00 AM"; + //Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime); + //if (String.Equals(currentDate, activateDate) && String.Equals(currentTime, activateTime)) + //{ + //ArchiveManager archive = new ArchiveManager(datasource); + //archive.Controller(); + //} + //} @@ -132,87 +179,85 @@ namespace TeamHobby.HobbyProjectGenerator.Main //datasource.WriteData(sqlRemove); //Console.WriteLine("Writing completed. "); + /* bool MainMenu = true; - /* ExampleDAO z = new ExampleDAO(); - z.UserData("Tomato"); - Console.Read();*/ - /*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(); - UserAccount user = new UserAccount(); + // 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: - 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(); + 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(); - // 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/ExampleDAO.cs b/Source Code/main/SqlDAO.cs similarity index 58% rename from Source Code/main/ExampleDAO.cs rename to Source Code/main/SqlDAO.cs index 64e3b63..8e331a7 100644 --- a/Source Code/main/ExampleDAO.cs +++ b/Source Code/main/SqlDAO.cs @@ -1,23 +1,22 @@ using Microsoft.Data.SqlClient; +using TeamHobby.HobbyProjectGenerator.Models; -namespace TeamHobby.HobbyProjectGenerator.Main +namespace TeamHobby.HobbyProjectGenerator.DAL { - public class ExampleDAO + public class SqlDAO { - - public void UserData(string username) + public IList GetUserData(string username) { // Sql server connection string, needs to be changed accordingly to connect - var connString = "server=localhost,3316;user=root;database=users;password=Plop20"; // Using @" " makes the string literal - + var connString = "server=localhost;userid=root;password=Plop20;database=users"; // Using @" " makes the string literal + // ADO.NET - ODBC - using var conn = new SqlConnection(connString); + using (var conn = new SqlConnection(connString)) { // More complex sql commands are done in this method instead var sql = "Select * from roles"; using (var command = new SqlCommand(sql, conn)) { - conn.Open(); // Get the results from the query SqlDataReader r = command.ExecuteReader(); @@ -33,18 +32,18 @@ namespace TeamHobby.HobbyProjectGenerator.Main { Console.WriteLine(r.ToString()); } - conn.Close(); - + return null; } - // Console.Read(); - /* - * this is meant for specific basic sql commands - using (var adapter = new SqlDataAdapter()) - { - adapter.SelectCommand - } - */ - //return null; + + /*// this is meant for specific basic sql commands + using (var adapter = new SqlDataAdapter()) + { + adapter.UpdateCommand + adapter.DeleteCommand + adapter.InsertCommand + adapter.SelectCommand + }*/ + } } } diff --git a/Source Code/main/SystemAccountManager.cs b/Source Code/main/SystemAccountManager.cs deleted file mode 100644 index 78a9ff3..0000000 --- a/Source Code/main/SystemAccountManager.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace main -{ - internal class SystemAccountManager - { - /*public NewUserName() - { - - } - public NewPassword() - { - // Create bool value for password confirm loop - bool conPsswrd = true; - // Loop until password is confirmed - while (conPsswrd == true) - { - // 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(); - - // Call user manager method to create the new user - //int userCreateConfirm = new CreateUser(userName,userPassword,SecQuest,SecAnswer); - - // Check if user creation was successful - /*if (userCreateConfirm = 1) - { - - // Confirm to user that the account has been created - Console.WriteLine("Account created succesfully with the username of" + userName); - } - 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(); - // - - } - - } - - } -} diff --git a/Source Code/main/UiPrint.cs b/Source Code/main/UiPrint.cs deleted file mode 100644 index 98378f8..0000000 --- a/Source Code/main/UiPrint.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -// Print Statements used throughout the program. - -namespace main -{ - internal 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 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"); - } - } -} diff --git a/Source Code/main/UserAccount.cs b/Source Code/main/UserAccount.cs deleted file mode 100644 index 92e0c55..0000000 --- a/Source Code/main/UserAccount.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace main -{ - public class UserAccount - { - /* private string username; - private string password; - private string role; - - public UserAccount(string un,string pwd,string rol) - { - username = un; - password = pwd; - role = rol; - - } - - public void UserAccount() - { - password = "1234"; - role = "Regular"; - } - - public void newUser() - { - - }*/ - } -} diff --git a/Source Code/main/main - Backup.csproj b/Source Code/main/main - Backup.csproj index 8853c02..73a9e47 100644 --- a/Source Code/main/main - Backup.csproj +++ b/Source Code/main/main - Backup.csproj @@ -5,6 +5,8 @@ net6.0 enable enable + AnyCPU + AnyCPU @@ -14,6 +16,8 @@ + + diff --git a/Source Code/main/main.csproj b/Source Code/main/main.csproj index 5dde81b..b25874c 100644 --- a/Source Code/main/main.csproj +++ b/Source Code/main/main.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/doc/Business Docs/Test_Plan.pdf b/doc/Business Docs/Test_Plan.pdf index a6ffa3a..9c06802 100644 Binary files a/doc/Business Docs/Test_Plan.pdf and b/doc/Business Docs/Test_Plan.pdf differ diff --git a/doc/LowLevel/Logging/Logging_LLD_v6.png b/doc/LowLevel/Logging/Logging_LLD_v6.png new file mode 100644 index 0000000..9cc93b9 Binary files /dev/null and b/doc/LowLevel/Logging/Logging_LLD_v6.png differ diff --git a/src/dbCode/UserManagementDDL.txt b/src/dbCode/UserManagementDDL.txt new file mode 100644 index 0000000..c8419fc --- /dev/null +++ b/src/dbCode/UserManagementDDL.txt @@ -0,0 +1,33 @@ +create table users +( + UserName varchar(50) charset utf8mb3 not null, + Password varchar(50) charset utf8mb3 not null, + Role varchar(50) charset utf8mb3 not null, + IsActive int default 1 not null, + CreatedBy varchar(50) charset utf8mb3 not null, + CreatedDate datetime not null, + constraint userRole_fk foreign key (Role) references roles (Role), + constraint user_pk primary key (UserName) +); + +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'), +('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; + + +