From a4a133b0cd299aa6fe725f6797b939405e3d4a7c Mon Sep 17 00:00:00 2001 From: Im_Alpha Date: Mon, 13 Dec 2021 23:28:47 -0800 Subject: [PATCH] Menu completed Commented out database connecting lines and added successful login in instead. --- .../Implementations/SqlDAO.cs | 4 +- .../Implementations/UiPrint.cs | 3 +- .../SystemAccountManager.cs | 5 +- Source Code/main/Controller.cs | 85 ++++++++++--------- 4 files changed, 52 insertions(+), 45 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 7a14a05..d7bf3e1 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.DataAccess/Implementations/UiPrint.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/UiPrint.cs index e197fbb..e94b6be 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/UiPrint.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/UiPrint.cs @@ -17,7 +17,8 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { // Menu for all UserManagement options int menu = 0; - Console.WriteLine($"Welcome {username} to User Management.\n"); + Console.WriteLine("-------------------------------------\n"); + Console.WriteLine($"\nWelcome {username} to User Management.\n"); Console.WriteLine("What would you like to do?\n"); Console.WriteLine(menu + ") To exit User Management.\n"); menu += 1; diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs index 954d9fa..a159178 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.UserManagement/SystemAccountManager.cs @@ -175,6 +175,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement if (checkSql == "Admin") { + Console.WriteLine("-- Logged in successfully."); return true; } else @@ -218,7 +219,6 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement // Exit menu case 0: return "Exiting UserManagement.\n"; - break; // Create account case 1: UserAccount newUser = new UserAccount(newCredentials.GetUserName(), @@ -266,8 +266,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement case 7: break; default: - Console.WriteLine("Invalid input.\nPlease enter a valid option.\n" + - "------------------------------------\n\n"); + Console.WriteLine("Invalid input.\nPlease enter a valid option.\n"); break; } } diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index 47ae7e5..da78001 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -33,51 +33,58 @@ 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 // Logger log = new Logger(); //Logger.PrintTest(); - // Admin login - GetCredentials credentials = new GetCredentials(); - string? username = credentials.GetUserName(); - string? password = credentials.GetPassword(); + // Loop login terminal + bool mainMenu = true; + + // Loop Admin login + while (mainMenu is true) + { + // Admin Sign in + GetCredentials credentials = new GetCredentials(); + Console.WriteLine("\nPlease Enter Admin Credentials.\n"); + string? username = credentials.GetUserName(); + string? password = credentials.GetPassword(); + + // Get time of login attempt + DateTime TimeStamp = DateTime.UtcNow; + + // String for checking query return type + string dbType = "sql"; + // Creating the Factory class + RDSFactory dbFactory = new RDSFactory(); + + // Testing Data Access Layer + string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + + "TCPIP=1;" + + "SERVER=localhost;" + + "DATABASE=hobby;" + + "UID=root;" + + "PASSWORD=Teamhobby;" + + "OPTION=3"; + IDataSource datasource = dbFactory.getDataSource(dbType, dbInfo); + // Create manager class from UserManagement + SystemAccountManager manager = new SystemAccountManager(); + + // Create UserAccount class + UserAccount user = new UserAccount(username, password, TimeStamp); + + string isLogin = manager.CreateUserRecord(user, datasource); - //Console.WriteLine(value: $"username is {username}\npassword is {password}"); - - // Creating the Factory class - // Creating the Factory class - - string dbType = "sql"; - RDSFactory dbFactory = new RDSFactory(); - - // Testing Data Access Layer - string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + - "TCPIP=1;" + - "SERVER=localhost;" + - "DATABASE=hobby;" + - "UID=root;" + - "PASSWORD=Teamhobby;" + - "OPTION=3"; - IDataSource datasource = dbFactory.getDataSource(dbType, dbInfo); - // Create manager class from UserManagement - SystemAccountManager manager = new SystemAccountManager(); - - /* // Admin Sign in - GetCredentials credentials = new GetCredentials(); - string? username = credentials.GetUserName(); - string? password = credentials.GetPassword();*/ - - // Get time of login attempt - DateTime TimeStamp = DateTime.UtcNow; - - // Create UserAccount class - UserAccount user = new UserAccount(username, password, TimeStamp); - - Console.Write(manager.CreateUserRecord(user, datasource)); - + if (isLogin != "Access Denied: Unauthorized\n") + { + mainMenu = false; + } + else + { + Console.WriteLine("******Access Denied: Unauthorized******"); + } + + } //Console.WriteLine(value: $"Welcome {username}\n"); /* string sqlQuery = "Select * from log;";