From af21f771d02c3ce7eac15d9b5174fce45382b97c Mon Sep 17 00:00:00 2001 From: colincreasman Date: Sun, 12 Dec 2021 15:02:57 -0800 Subject: [PATCH 01/14] add ignore json add ignore json --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 079a604..e1b4559 100644 --- a/.gitignore +++ b/.gitignore @@ -423,3 +423,5 @@ healthchecksdb .vscode/launch.json .vscode/tasks.json +Source Code/.vscode/tasks.json +Source Code/.vscode/launch.json From 4a2bd5b38f4e3c7ff1448663933a0602cc96ed59 Mon Sep 17 00:00:00 2001 From: Alatreon Date: Sun, 12 Dec 2021 16:21:02 -0800 Subject: [PATCH 02/14] Add error handling an cleaning up for Archiving --- .../ArchiveManager.cs | 116 +++++++++++------- .../Implementations/SqlDAO.cs | 14 +-- Source Code/main/Controller.cs | 1 - 3 files changed, 79 insertions(+), 52 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs index 256ce31..5cd427e 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs @@ -22,18 +22,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 +98,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 +114,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 +127,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.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 1843b50..5adaed0 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -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/main/Controller.cs b/Source Code/main/Controller.cs index 0dee3c0..9b0f0dd 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -4,7 +4,6 @@ using System.Data.Odbc; using TeamHobby.HobbyProjectGenerator.Archive; using TeamHobby.HobbyProjectGenerator.DataAccess; - namespace TeamHobby.HobbyProjectGenerator.Main { public class GetCredentials From e8d42bf98f9cecc5efd55f3afd88a59277779d04 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Sun, 12 Dec 2021 20:56:34 -0800 Subject: [PATCH 03/14] Creating test methods for archiving --- .../ArchivingTests.cs | 110 ++++++++++++++++++ ....HobbyProjectGenerator.ArchiveTests.csproj | 14 +++ .../TeamHobby.HobbyProjectGenerator.sln | 8 +- 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs new file mode 100644 index 0000000..0846dc2 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs @@ -0,0 +1,110 @@ +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 CreateFolderTest(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 CreateFileNameTest(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 FolderCreationFailed() + { + + } + + 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.CreateFolderTest(sqlDAO); + Console.WriteLine("-----------------"); + Console.WriteLine(""); + + // Testing file creation + test.CreateFileNameTest(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/TeamHobby.HobbyProjectGenerator.sln b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln index 2e9cc83..bff6309 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln @@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGener EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.Main", "..\TeamHobby.Main\TeamHobby.Main.csproj", "{ED126EFB-B337-42F9-BE4B-65A5AE90503B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.DataAccess", "..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj", "{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.DataAccess", "..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj", "{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}" +EndProject +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 @@ -48,6 +50,10 @@ Global {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 + {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 + {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From a76603f00c77c1c2d8d0019cc3579de4f97e3c80 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Sun, 12 Dec 2021 22:42:20 -0800 Subject: [PATCH 04/14] Rearrange Low level diagrams into a folder. --- .../ArchiveManager.cs | 4 ++++ .../ArchivingTests.cs | 15 ++++++++++++++- .../Implementations/SqlDAO.cs | 2 +- .../{ => ArchivingLL}/ArchivingWithError.png | Bin .../{ => ArchivingLL}/ArchivingWithError.svg | 0 .../{ => ArchivingLL}/ArchivingWithError.txt | 0 .../{ => ArchivingLL}/ArchivingWithSingleton.pdf | Bin .../{ => ArchivingLL}/ArchvingMasterCon.txt | 0 doc/LowLevel/{ => ArchivingLL}/archiving.pdf | Bin doc/LowLevel/{ => ArchivingLL}/archiving.txt | 0 doc/LowLevel/{ => ArchivingLL}/archiving2.png | Bin doc/LowLevel/{ => ArchivingLL}/archiving2.txt | 0 .../{ => ArchivingLL}/archivingMasterCon.pdf | Bin .../{ => ArchivingLL}/archivingSubmission.pdf | Bin .../{ => ArchivingLL}/archivingWithError.pdf | Bin .../{ => ArchivingLL}/archivingWithError2.pdf | Bin doc/LowLevel/{ => ArchivingLL}/archiving_5.txt | 0 .../{ => ArchivingLL}/archivngWithError.txt | 0 .../{ => ArchivingLL}/arcvhingMasterCon.pdf | Bin 19 files changed, 19 insertions(+), 2 deletions(-) rename doc/LowLevel/{ => ArchivingLL}/ArchivingWithError.png (100%) rename doc/LowLevel/{ => ArchivingLL}/ArchivingWithError.svg (100%) rename doc/LowLevel/{ => ArchivingLL}/ArchivingWithError.txt (100%) rename doc/LowLevel/{ => ArchivingLL}/ArchivingWithSingleton.pdf (100%) rename doc/LowLevel/{ => ArchivingLL}/ArchvingMasterCon.txt (100%) rename doc/LowLevel/{ => ArchivingLL}/archiving.pdf (100%) rename doc/LowLevel/{ => ArchivingLL}/archiving.txt (100%) rename doc/LowLevel/{ => ArchivingLL}/archiving2.png (100%) rename doc/LowLevel/{ => ArchivingLL}/archiving2.txt (100%) rename doc/LowLevel/{ => ArchivingLL}/archivingMasterCon.pdf (100%) rename doc/LowLevel/{ => ArchivingLL}/archivingSubmission.pdf (100%) rename doc/LowLevel/{ => ArchivingLL}/archivingWithError.pdf (100%) rename doc/LowLevel/{ => ArchivingLL}/archivingWithError2.pdf (100%) rename doc/LowLevel/{ => ArchivingLL}/archiving_5.txt (100%) rename doc/LowLevel/{ => ArchivingLL}/archivngWithError.txt (100%) rename doc/LowLevel/{ => ArchivingLL}/arcvhingMasterCon.pdf (100%) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs index 5cd427e..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(){ diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs index 0846dc2..869ee4e 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs @@ -75,8 +75,21 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests } - public void FolderCreationFailed() + public void CopyingToAFileTest(IDataSource sqlDAO) { + // Arrange + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + SqlDAO sqlDS = null; + + if (sqlDAO.GetType() == typeof(SqlDAO)) + { + sqlDS = (SqlDAO)sqlDAO; + } + + // Act + + + // Assert } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 5adaed0..06b919b 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -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; } 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 From c118c908f1647c8b56c12e420249761134454f08 Mon Sep 17 00:00:00 2001 From: colincreasman Date: Sun, 12 Dec 2021 23:49:59 -0800 Subject: [PATCH 05/14] Removed old svg --- doc/LowLevel/Logging/LogToFile_Sequence.svg | 1 - 1 file changed, 1 deletion(-) delete mode 100644 doc/LowLevel/Logging/LogToFile_Sequence.svg diff --git a/doc/LowLevel/Logging/LogToFile_Sequence.svg b/doc/LowLevel/Logging/LogToFile_Sequence.svg deleted file mode 100644 index 0796128..0000000 --- a/doc/LowLevel/Logging/LogToFile_Sequence.svg +++ /dev/null @@ -1 +0,0 @@ -title%20Log%20Event%20to%20File%20%0A%0Aparticipant%20Controller.cs%20%23lightgreen%0Aparticipant%20LoggingManager%20%23ffffe0%0Aparticipant%20LogEntry%20%23cbc3e3%0Aparticipant%20FileLoggerFactory%20%23ff8b3d%0Aparticipant%20FileLogger%20%23D3D3D3%0A%0A%0A%0A%0A%5B-%3EController.cs%3Arequest%20to%20log%20event%20to%20file%0Aactivate%20Controller.cs%20%23lightgreen%0A%0AController.cs-%3ELoggingManager%3Amanager%20%3D%20new%20LoggingManager()%0A%0Aactivate%20LoggingManager%20%23ffffe0%0A%0ALoggingManager-%3ELoggingManager%3AConstructor()%0A%0ALoggingManager-%3ELogEntry%3A_logEntry%20%3D%20new%20LogEntry(int%20userID%2C%5CnDateTime%20timestamp%2C%20string%20level%2C%20%5Cnstring%20category%2C%20string%20message)%0A%0Aactivate%20LogEntry%20%23cbc3e3%0A%0A%0ALogEntry-%3ELogEntry%3AConstuctor(int%20userID%2C%5Cnstring%20level%2C%20%5CnDateTime%20timestamp%2C%5Cnstring%20category%2C%5Cnstring%20description)%0ALoggingManager%3C--LogEntry%3Areturn%20new%20LogEntry()%0A%0Adeactivate%20LogEntry%0ALoggingManager-%3EFileLoggerFactory%3A_loggerFactory%20%3D%20new%20FileLoggerFactory()%0Aactivate%20FileLoggerFactory%20%23ff8b3d%0A%0AFileLoggerFactory-%3EFileLoggerFactory%3A%20Constructor()%0A%0ALoggingManager%3C--FileLoggerFactory%3Areturn%20new%20FileLoggerFactory%0ALoggingManager-%3EFileLoggerFactory%3A_logger%20%3D%20_loggerFactory.CreateLogger()%0AFileLoggerFactory-%3EFileLogger%3A%20new%20FileLogger()%0A%0A%0Aactivate%20FileLogger%20%23D3D3D3%0AFileLogger-%3EFileLogger%3AConstructor()%0A%0ALoggingManager%3C--FileLogger%3Areturn%20new%20FileLogger()%0Adeactivate%20FileLoggerFactory%0A%0ALoggingManager-%3EFileLogger%3A_logger.Log(_logEntry)%0A%0Adeactivate%20LoggingManager%0AFileLogger-%3EFileLogger%3AAppendFile(LogEntry)%0A%0A%0Aalt%20%23red%20file%20not%20found%20%0AFileLogger-%3EFileLogger%3ACreateFile()%0A%0Aend%0A%0Aalt%20%23red%20insufficient%20storage%20capacity%20%0AFileLogger-%3EFileLogger%3A%20new%20IOException()%0A%0AController.cs%3C--FileLogger%3Areturn%20new%20IOException()%0Aend%20%0ALog Event to File Controller.csLoggingManagerLogEntryFileLoggerFactoryFileLoggerrequest to log event to filemanager = new LoggingManager()Constructor()_logEntry = new LogEntry(int userID,DateTime timestamp, string level, string category, string message)Constuctor(int userID,string level, DateTime timestamp,string category,string description)return new LogEntry()_loggerFactory = new FileLoggerFactory()Constructor()return new FileLoggerFactory_logger = _loggerFactory.CreateLogger()new FileLogger()Constructor()return new FileLogger()_logger.Log(_logEntry)AppendFile(LogEntry)CreateFile()new IOException()return new IOException()alt[file not found ]alt[insufficient storage capacity ] \ No newline at end of file From f67b172f8d69790b216414b0b8b4d7d77a7f9b85 Mon Sep 17 00:00:00 2001 From: Im_Alpha Date: Mon, 13 Dec 2021 06:29:13 -0800 Subject: [PATCH 06/14] Finished isAdmin, working on submenu --- .../SystemAccountManager.cs | 87 ++++++++- ...obbyProjectGenerator.UserManagement.csproj | 1 + .../UserAccount.cs | 57 +++--- Source Code/main/Controller.cs | 176 ++++++++---------- 4 files changed, 198 insertions(+), 123 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs index 9cb4617..14e948d 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs @@ -3,8 +3,10 @@ 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 { @@ -51,17 +53,88 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement } else { - return "Invalid Input\n"; + return "Invalid input\n"; } } - public bool isAdmin() + // Check with database if user is an admin + public bool isAdmin(UserAccount user, IDataSource dbSource) { - return false; - } - public void CreateUserRecord(UserAccount user) - { - Console.Write(IsInputValid(user.username, user.password)); + // select r.Role from roles r, users u where UserName = '{user.username}' and Password = '{user.password}' and r.RoleID = u.RoleID; + // 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.RoleID = u.RoleID;"; + 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) + + // 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."); + + + + + // Notify user of new credentials to be input + Console.WriteLine("Please enter the new user information:\n"); + GetCredentials credentials = new GetCredentials(); + + + + string dbAction = user.NewUserName; + 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..8141c68 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/TeamHobby.HobbyProjectGenerator.UserManagement.csproj +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/TeamHobby.HobbyProjectGenerator.UserManagement.csproj @@ -7,6 +7,7 @@ + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs index 687f7ec..902bb2b 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs @@ -6,37 +6,52 @@ 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 class UserAccount { // Admin Credentials - private string UserName; - private string Password; - private DateTime Time; + private string _userName; + private string _password; + private DateTime _logginTime; public UserAccount(string un, string pwd, DateTime TimeStamp) { - UserName = un; - Password = pwd; - Time = TimeStamp; + _userName = un; + _password = pwd; + _logginTime = TimeStamp; } - public string username { get { return UserName; } } - public string password { get { return Password; } } + 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) + private string _newUserName; + private string _newPassword; + private string _newEmail; + private DateTime _newTime; + public UserAccount(string newUN, string newPWD, string Email, DateTime newTime) { - newusername = newUN; - newpassword = newPWD; - newemail = Email; - newtime = newTime; + _newUserName = newUN; + _newPassword = newPWD; + _newEmail = Email; + _newTime = 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 string NewUserName { get { return _newUserName; } } + public string NewPassword { get { return _newPassword; } } + public string NewEmail { get { return _newEmail; } } + public DateTime Newtime { get { return _newTime; } } } } diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index 5d30baa..0166aad 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -7,26 +7,11 @@ using TeamHobby.HobbyProjectGenerator.UserManagement; namespace TeamHobby.HobbyProjectGenerator.Main { - 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 class Controller { public static void Main(string[] args) { - /*// Creating the Factory class + // Creating the Factory class string dbType = "sql"; RDSFactory factory = new RDSFactory(); @@ -37,7 +22,7 @@ namespace TeamHobby.HobbyProjectGenerator.Main "UID=root;" + "PASSWORD=Teamhobby;" + "OPTION=3"; - IDataSource datasource = factory.getDataSource(dbType, dbInfo);*/ + IDataSource datasource = factory.getDataSource(dbType, dbInfo); // Create manager class from UserManagement SystemAccountManager manager = new SystemAccountManager(); @@ -53,11 +38,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; @@ -79,18 +64,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(); + } + //}*/ @@ -122,7 +108,7 @@ namespace TeamHobby.HobbyProjectGenerator.Main //// Remove entries fromt the database //sqlDS.RemoveEntries(); - + // 2.Inserting Data into the database: @@ -139,80 +125,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: - 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; + };*/ //} } From 55ab7c6cf297256bf37ba5a1cdcce1d5bdd78d64 Mon Sep 17 00:00:00 2001 From: Im_Alpha Date: Mon, 13 Dec 2021 07:17:44 -0800 Subject: [PATCH 07/14] updated menu and uiprint working on menu switch still and rearranged project folders --- .../Implementations/UiPrint.cs | 39 ++++++++++++++ .../SystemAccountManager.cs | 44 ++++++++------- ...obbyProjectGenerator.UserManagement.csproj | 1 - .../Implementations/InMemoryUserService.cs | 53 ------------------- .../Implementations/UiPrint.cs | 17 +++--- .../Implementations/User_Authentication.cs | 17 ------ .../Implementations/User_Manager.cs | 21 -------- .../TeamHobby.HobbyProjectGenerator.sln | 6 --- .../TeamHobby.UserManagement.Tests.csproj | 4 -- Source Code/main/Controller.cs | 8 +++ Source Code/main/main.csproj | 1 - 11 files changed, 82 insertions(+), 129 deletions(-) create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/UiPrint.cs delete mode 100644 Source Code/TeamHobby.HobbyProjectGenerator/Implementations/InMemoryUserService.cs delete mode 100644 Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Authentication.cs delete mode 100644 Source Code/TeamHobby.HobbyProjectGenerator/Implementations/User_Manager.cs 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..3f31b36 --- /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/SystemAccountManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs index 14e948d..9ff8082 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs @@ -5,7 +5,6 @@ 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 @@ -112,17 +111,29 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement { // db.users layout (UserName, Password, RoleID, IsActive, CreatedBy, CreatedDate) // db.roles layout (RoleID(AutoGen), Role, CreatedBy, CreatedDate) - - // 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."); - + // Create UiPrint Object + UiPrint ui = new UiPrint(); + // 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) + { + case 0: + return "Exiting UserManagement.\n"; + break; + case 1: + break; + default: + Console.WriteLine("Invalid input.\nPlease enter a valid option.\n"); + break; + } + } @@ -196,14 +207,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement bool foo = true; - while (foo == true) - { - // sub menu - ui.SystemAccountMenu(); - // - - } - + } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/TeamHobby.HobbyProjectGenerator.UserManagement.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/TeamHobby.HobbyProjectGenerator.UserManagement.csproj index 8141c68..be6931d 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/TeamHobby.HobbyProjectGenerator.UserManagement.csproj +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/TeamHobby.HobbyProjectGenerator.UserManagement.csproj @@ -8,7 +8,6 @@ - diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/InMemoryUserService.cs b/Source Code/TeamHobby.HobbyProjectGenerator/Implementations/InMemoryUserService.cs deleted file mode 100644 index db60f66..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 c92ae09..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 3d463a9..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 b41037d..5234556 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}" @@ -25,10 +23,6 @@ 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}.Debug|Any CPU.Build.0 = 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 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 0166aad..dad01c3 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -11,6 +11,14 @@ namespace TeamHobby.HobbyProjectGenerator.Main { 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; + // Creating the Factory class string dbType = "sql"; RDSFactory factory = new RDSFactory(); diff --git a/Source Code/main/main.csproj b/Source Code/main/main.csproj index 463e46e..c203f89 100644 --- a/Source Code/main/main.csproj +++ b/Source Code/main/main.csproj @@ -16,7 +16,6 @@ - From 6414c9feed814d29b7fb304d4db66a8197515bf5 Mon Sep 17 00:00:00 2001 From: Im_Alpha Date: Mon, 13 Dec 2021 09:12:51 -0800 Subject: [PATCH 08/14] menu finished, requires logs and archive menu is done and also overloaded GetCredentials and isInputValid to accomodate the new user credentials when creating an account --- .../Implementations/UiPrint.cs | 2 +- .../AccountService.cs | 22 ++- .../SystemAccountManager.cs | 152 ++++++++++++++++-- .../UserAccount.cs | 19 ++- 4 files changed, 176 insertions(+), 19 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/UiPrint.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/UiPrint.cs index 3f31b36..e197fbb 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/UiPrint.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/UiPrint.cs @@ -33,7 +33,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess menu += 1; Console.WriteLine(menu + ") View logs.\n"); menu += 1; - Console.WriteLine(menu + ") View Archive.\n"); + 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..578c9d7 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs @@ -6,7 +6,27 @@ using System.Threading.Tasks; namespace TeamHobby.HobbyProjectGenerator.UserManagement { - internal class AccountService + public class AccountService { + public bool CreateUserRecord(UserAccount newUser) + { + return true; + } + public bool EditUserRecord(UserAccount newUser) + { + return true; + } + public bool DeleteUserRecord(UserAccount newUser) + { + return true; + } + public bool DisableUser(UserAccount newUser) + { + return true; + } + public bool EnableUser(UserAccount newUser) + { + return true; + } } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs index 9ff8082..8318853 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs @@ -14,39 +14,127 @@ 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"; + } + } + 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"; } @@ -113,6 +201,10 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement // 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 @@ -124,24 +216,52 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement // 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); + break; + // Edit account + case 2: + UserAccount newEditUser = new UserAccount(newCredentials.GetUserName(), + newCredentials.GetPassword(), DateTime.UtcNow); + accountService.EditUserRecord(newEditUser); + break; + // Delete account + case 3: + UserAccount newDeleteUser = new UserAccount(newCredentials.GetUserName(), + newCredentials.GetPassword(), DateTime.UtcNow); + accountService.DeleteUserRecord(newDeleteUser); + break; + // Disable account + case 4: + UserAccount newDisableUser = new UserAccount(newCredentials.GetUserName(), + newCredentials.GetPassword(), DateTime.UtcNow); + accountService.DisableUser(newDisableUser); + break; + // Enable account + case 5: + UserAccount newEnableUser = new UserAccount(newCredentials.GetUserName(), + newCredentials.GetPassword(), DateTime.UtcNow); + accountService.EnableUser(newEnableUser); + break; + // View logs + case 6: + break; + // View archive + case 7: break; default: Console.WriteLine("Invalid input.\nPlease enter a valid option.\n"); break; } } - - - - // Notify user of new credentials to be input - Console.WriteLine("Please enter the new user information:\n"); - GetCredentials credentials = new GetCredentials(); - - string dbAction = user.NewUserName; return dbAction; diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs index 902bb2b..b75ac3b 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs @@ -20,6 +20,16 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement string? userPassword = Console.ReadLine(); return userPassword; } + 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 { @@ -41,14 +51,21 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement private string _newUserName; private string _newPassword; private string _newEmail; + private string _role; private DateTime _newTime; - public UserAccount(string newUN, string newPWD, string Email, DateTime newTime) + public UserAccount(string newUN, string newPWD, string Email, string role, DateTime newTime) { _newUserName = newUN; _newPassword = newPWD; + _role = role; _newEmail = Email; _newTime = newTime; } + public UserAccount() + { + _role = "regular"; + _newTime= DateTime.Now; + } public string NewUserName { get { return _newUserName; } } public string NewPassword { get { return _newPassword; } } public string NewEmail { get { return _newEmail; } } From b2a627a9c7df0b36963b72f243657f6042b3ee2a Mon Sep 17 00:00:00 2001 From: Im_Alpha Date: Mon, 13 Dec 2021 15:37:58 -0800 Subject: [PATCH 09/14] added create account record --- .../Implementations/SqlDAO.cs | 4 +- .../AccountService.cs | 56 ++++++++++++++++--- .../SystemAccountManager.cs | 11 ++-- .../UserAccount.cs | 9 +-- Source Code/main/Controller.cs | 2 + 5 files changed, 62 insertions(+), 20 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 1843b50..6287a39 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; diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs index 578c9d7..8a37d9c 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs @@ -3,28 +3,68 @@ 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) + public bool CreateUserRecord(UserAccount newUser, IDataSource dbSource) + { + // string checkAdmin = $"Select * from users where username = {user.username} and password = {user.password};"; + // Insert into users table + string sqlUser = $"INSERT INTO hobby.users (UserName, Password," + + $"CreatedBy, CreatedDate, Email) VALUES ('{newUser.NewUserName}', " + + $"'{newUser.NewPassword}','{newUser.username}', NOW(),'{newUser.NewEmail}');"; + + Object insertNewUser = dbSource.WriteData(sqlUser); + // Insert into users table + string sqlRoles = $"INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) " + + $"VALUES ('{newUser.NewRole}', '{newUser.username}', 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.WriteData(confirmUser); + + //Console.WriteLine("type of Reesult:" + confirmAdmin.GetType()); + OdbcDataReader reader = null; + + if (conUser.GetType() == typeof(OdbcDataReader)) + { + reader = (OdbcDataReader)conUser; + } + + // Create String to hold sql output + string checkSql = ""; + + // 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 EditUserRecord(UserAccount newUser, IDataSource dbSource) { return true; } - public bool EditUserRecord(UserAccount newUser) + public bool DeleteUserRecord(UserAccount newUser, IDataSource dbSource) { return true; } - public bool DeleteUserRecord(UserAccount newUser) + public bool DisableUser(UserAccount newUser, IDataSource dbSource) { return true; } - public bool DisableUser(UserAccount newUser) - { - return true; - } - public bool EnableUser(UserAccount newUser) + 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 8318853..47ab78a 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs @@ -146,7 +146,6 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement // Check with database if user is an admin public bool isAdmin(UserAccount user, IDataSource dbSource) { - // select r.Role from roles r, users u where UserName = '{user.username}' and Password = '{user.password}' and r.RoleID = u.RoleID; // 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.RoleID = u.RoleID;"; @@ -225,31 +224,31 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement UserAccount newUser = new UserAccount(newCredentials.GetUserName(), newCredentials.GetPassword(), newCredentials.GetEmail(), newCredentials.GetRole(), DateTime.UtcNow); - accountService.CreateUserRecord(newUser); + accountService.CreateUserRecord(newUser, dbSource); break; // Edit account case 2: UserAccount newEditUser = new UserAccount(newCredentials.GetUserName(), newCredentials.GetPassword(), DateTime.UtcNow); - accountService.EditUserRecord(newEditUser); + accountService.EditUserRecord(newEditUser, dbSource); break; // Delete account case 3: UserAccount newDeleteUser = new UserAccount(newCredentials.GetUserName(), newCredentials.GetPassword(), DateTime.UtcNow); - accountService.DeleteUserRecord(newDeleteUser); + accountService.DeleteUserRecord(newDeleteUser, dbSource); break; // Disable account case 4: UserAccount newDisableUser = new UserAccount(newCredentials.GetUserName(), newCredentials.GetPassword(), DateTime.UtcNow); - accountService.DisableUser(newDisableUser); + accountService.DisableUser(newDisableUser, dbSource); break; // Enable account case 5: UserAccount newEnableUser = new UserAccount(newCredentials.GetUserName(), newCredentials.GetPassword(), DateTime.UtcNow); - accountService.EnableUser(newEnableUser); + accountService.EnableUser(newEnableUser, dbSource); break; // View logs case 6: diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs index b75ac3b..3911cb4 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs @@ -51,24 +51,25 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement private string _newUserName; private string _newPassword; private string _newEmail; - private string _role; + private string _newRole; private DateTime _newTime; public UserAccount(string newUN, string newPWD, string Email, string role, DateTime newTime) { _newUserName = newUN; _newPassword = newPWD; - _role = role; + _newRole = role; _newEmail = Email; _newTime = newTime; } public UserAccount() { - _role = "regular"; + _newRole = "regular"; _newTime= DateTime.Now; } 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 string NewRole { get { return _newRole; } } + public DateTime NewTime { get { return _newTime; } } } } diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index dad01c3..066b3cc 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -19,6 +19,8 @@ namespace TeamHobby.HobbyProjectGenerator.Main // Change terminal height Console.WindowHeight = 40; + Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")); + // Creating the Factory class string dbType = "sql"; RDSFactory factory = new RDSFactory(); From 9e1ef7bcabd0e49781d4d494a9da3d440c8cb8fc Mon Sep 17 00:00:00 2001 From: Im_Alpha Date: Mon, 13 Dec 2021 15:39:38 -0800 Subject: [PATCH 10/14] added users and roles table to ddl --- src/dbCode/fullDDL.txt | 152 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/dbCode/fullDDL.txt 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; + + + From 307404477726b1c2fc1eba25a4d5fdac689246b8 Mon Sep 17 00:00:00 2001 From: Im_Alpha Date: Mon, 13 Dec 2021 15:40:21 -0800 Subject: [PATCH 11/14] created usermanagement standalone DDL --- src/dbCode/UserManagementDDL.txt | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/dbCode/UserManagementDDL.txt diff --git a/src/dbCode/UserManagementDDL.txt b/src/dbCode/UserManagementDDL.txt new file mode 100644 index 0000000..6feff6e --- /dev/null +++ b/src/dbCode/UserManagementDDL.txt @@ -0,0 +1,46 @@ +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); \ No newline at end of file From 65d41e0faa8771875aebf2b69eca3dfa82601ca4 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Mon, 13 Dec 2021 18:29:34 -0800 Subject: [PATCH 12/14] Rename the DataSource Factory --- .../ArchivingTests.cs | 8 ++++---- .../{RelationalDataSourceFactory.cs => RDSFactory.cs} | 2 +- Source Code/main/Controller.cs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/{RelationalDataSourceFactory.cs => RDSFactory.cs} (95%) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs index 869ee4e..88e7b50 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs @@ -19,7 +19,7 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests // [TestMethod] - public void CreateFolderTest(IDataSource sqlDAO) + public void IsArchiveFolderCreated(IDataSource sqlDAO) { // Arrange //SqlDAO sqlDAO = new SqlDAO(dbInfo); @@ -51,7 +51,7 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests } // [TestMethod] - public void CreateFileNameTest(IDataSource sqlDAO) + public void IsFileNameCreated(IDataSource sqlDAO) { // Arrange string foldPath = @"C:\HobbyArchive"; @@ -106,12 +106,12 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests // Testing folder creation ArchivingTests test = new ArchivingTests(); - test.CreateFolderTest(sqlDAO); + test.IsArchiveFolderCreated(sqlDAO); Console.WriteLine("-----------------"); Console.WriteLine(""); // Testing file creation - test.CreateFileNameTest(sqlDAO); + test.IsFileNameCreated(sqlDAO); Console.WriteLine("-----------------"); Console.WriteLine(""); diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/RelationalDataSourceFactory.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/RDSFactory.cs similarity index 95% rename from Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/RelationalDataSourceFactory.cs rename to Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/RDSFactory.cs index 656ebd1..6eb1899 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/RelationalDataSourceFactory.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/RDSFactory.cs @@ -7,7 +7,7 @@ using TeamHobby.HobbyProjectGenerator.DataAccess; namespace TeamHobby.HobbyProjectGenerator.DataAccess { - public class RelationalDataSourceFactory + public class RDSFactory { // Mehthod to create a specific data source suitable to the need public IDataSource getDataSource(string name, string info) diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index 9b0f0dd..33c1916 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -35,7 +35,7 @@ namespace TeamHobby.HobbyProjectGenerator.Main // Creating the Factory class string dbType = "sql"; - RelationalDataSourceFactory dbFactory = new RelationalDataSourceFactory(); + RDSFactory dbFactory = new RDSFactory(); // Testing Data Access Layer string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + From 80cd5c3de931765f2556cbaa39d55cc428cb64e0 Mon Sep 17 00:00:00 2001 From: Im_Alpha Date: Mon, 13 Dec 2021 19:56:47 -0800 Subject: [PATCH 13/14] fixed sql DDL --- src/dbCode/UserManagementDDL.txt | 46 +++++++++++++------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/dbCode/UserManagementDDL.txt b/src/dbCode/UserManagementDDL.txt index 6feff6e..a4022e6 100644 --- a/src/dbCode/UserManagementDDL.txt +++ b/src/dbCode/UserManagementDDL.txt @@ -3,44 +3,36 @@ create table users UserName varchar(50) charset utf8mb3 not null primary key, Password varchar(50) charset utf8mb3 null, - RoleID int auto_increment, + 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_RoleID_fk - foreign key (RoleID) references roles (RoleID) + constraint users_roles_Role_fk + foreign key (Role) references roles (Role) ); -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'); +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 auto_increment - primary key, - Role varchar(50) charset utf8mb3 null, - CreatedBy varchar(200) charset utf8mb3 null, - CreatedDate datetime null + 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', 'SystemCreator', '2021-12-13 03:25:14'); +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'); -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); \ No newline at end of file From c100a73b39e418da31395aba45234bb8c44133ea Mon Sep 17 00:00:00 2001 From: Im_Alpha Date: Mon, 13 Dec 2021 20:09:07 -0800 Subject: [PATCH 14/14] fixed create account sql and edit account --- Source Code/.vscode/launch.json | 26 +++++++ Source Code/.vscode/tasks.json | 42 ++++++++++ .../AccountService.cs | 45 ++++++----- .../SystemAccountManager.cs | 77 ++----------------- .../UserAccount.cs | 46 +++++------ 5 files changed, 125 insertions(+), 111 deletions(-) create mode 100644 Source Code/.vscode/launch.json create mode 100644 Source Code/.vscode/tasks.json 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.UserManagement/AccountService.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs index 8a37d9c..198f16c 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/AccountService.cs @@ -10,23 +10,39 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement { public class AccountService { - public bool CreateUserRecord(UserAccount newUser, IDataSource dbSource) + public bool CreateUserRecord(UserAccount newUser, string CreatedBy, IDataSource dbSource) { - // string checkAdmin = $"Select * from users where username = {user.username} and password = {user.password};"; - // Insert into users table - string sqlUser = $"INSERT INTO hobby.users (UserName, Password," + - $"CreatedBy, CreatedDate, Email) VALUES ('{newUser.NewUserName}', " + - $"'{newUser.NewPassword}','{newUser.username}', NOW(),'{newUser.NewEmail}');"; - + 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 hobby.roles (Role, CreatedBy, CreatedDate) " + - $"VALUES ('{newUser.NewRole}', '{newUser.username}', NOW());"; + 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.WriteData(confirmUser); + Object conUser = dbSource.ReadData(confirmUser); //Console.WriteLine("type of Reesult:" + confirmAdmin.GetType()); OdbcDataReader reader = null; @@ -36,9 +52,6 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement reader = (OdbcDataReader)conUser; } - // Create String to hold sql output - string checkSql = ""; - // Read Sql query results while (reader.Read()) { @@ -49,11 +62,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement Console.WriteLine(""); // Closing the connection - sqlDS.getConnection().Close(); - return true; - } - public bool EditUserRecord(UserAccount newUser, IDataSource dbSource) - { + sqlDS.getConnection().Close();*/ return true; } public bool DeleteUserRecord(UserAccount newUser, IDataSource dbSource) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs index 47ab78a..28d621e 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs @@ -148,7 +148,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement { // 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.RoleID = u.RoleID;"; + $"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; @@ -223,14 +223,14 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement case 1: UserAccount newUser = new UserAccount(newCredentials.GetUserName(), newCredentials.GetPassword(), newCredentials.GetEmail(), - newCredentials.GetRole(), DateTime.UtcNow); - accountService.CreateUserRecord(newUser, dbSource); + newCredentials.GetRole(), DateTime.UtcNow); + accountService.CreateUserRecord(newUser,user.username, dbSource); break; // Edit account case 2: - UserAccount newEditUser = new UserAccount(newCredentials.GetUserName(), + /* UserAccount newEditUser = new UserAccount(newCredentials.GetUserName(), newCredentials.GetPassword(), DateTime.UtcNow); - accountService.EditUserRecord(newEditUser, dbSource); + accountService.EditUserRecord(newEditUser, dbSource);*/ break; // Delete account case 3: @@ -262,72 +262,9 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement } } - string dbAction = user.NewUserName; + string dbAction = user.username; return dbAction; } - } - - - - /*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; - - - } - + } } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs index 3911cb4..4b9a38f 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/UserAccount.cs @@ -20,6 +20,11 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement string? userPassword = Console.ReadLine(); return userPassword; } + /*public string ConfirmPassword() + { + Console.WriteLine(); + string confirmPassword = newUser.NewPassword; + }*/ public string GetEmail() { Console.WriteLine("Please enter an email:"); @@ -36,40 +41,35 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement // Admin Credentials private string _userName; private string _password; - private DateTime _logginTime; + private DateTime _Time; + // New User Credentials + private string _Email; + private string _Role; public UserAccount(string un, string pwd, DateTime TimeStamp) { _userName = un; _password = pwd; - _logginTime = TimeStamp; + _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 string _newRole; - private DateTime _newTime; public UserAccount(string newUN, string newPWD, string Email, string role, DateTime newTime) { - _newUserName = newUN; - _newPassword = newPWD; - _newRole = role; - _newEmail = Email; - _newTime = newTime; + _userName = newUN; + _password = newPWD; + _Role = role; + _Email = Email; + _Time = newTime; } public UserAccount() { - _newRole = "regular"; - _newTime= DateTime.Now; + _Role = "regular"; + _Time= DateTime.Now; } - public string NewUserName { get { return _newUserName; } } - public string NewPassword { get { return _newPassword; } } - public string NewEmail { get { return _newEmail; } } - public string NewRole { get { return _newRole; } } - public DateTime NewTime { get { return _newTime; } } + + 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; } } } }