commit
89eda68a6c
@ -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;
|
||||
|
||||
@ -4,20 +4,12 @@ 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("-------------------------------------\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;
|
||||
@ -31,9 +23,9 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") Enable an account.\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") View logs.\n");
|
||||
Console.WriteLine(menu + ") View log path.\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") View archive.\n");
|
||||
Console.WriteLine(menu + ") View archive path.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
/*using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -14,3 +14,4 @@ namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
/*using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -14,3 +14,4 @@ namespace TeamHobby.HobbyProjectGenerator.Logging.Contracts
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
/*using System;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||
{
|
||||
@ -21,4 +21,4 @@ namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}*/
|
||||
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
/*using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -18,3 +18,4 @@ namespace TeamHobby.HobbyProjectGenerator.Logging.Implementations
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
/*using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -51,4 +51,3 @@ namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
/*using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -42,3 +42,4 @@ namespace TeamHobby.HobbyProjectGenerator.Logging
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
@ -29,53 +29,74 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool EditUserRecord(UserAccount newUser, string CreatedBy, IDataSource<string> dbSource)
|
||||
public bool EditUserRecord(UserAccount editUser, string CreatedBy, IDataSource<string> dbSource)
|
||||
{
|
||||
try
|
||||
{
|
||||
/* // Insert into users table
|
||||
string sqlUser = $"UPDATE hobby.roles r SET r.Role = 'regular',r.CreatedBy = 'colin'WHERE r.RoleID = 5; ";
|
||||
|
||||
Object insertNewUser = dbSource.WriteData(sqlUser);
|
||||
// Insert into users table
|
||||
string sqlRoles = $"INSERT INTO roles (Role, CreatedBy, CreatedDate) " +
|
||||
$"VALUES ('{newUser.NewRole}', '{CreatedBy}', NOW());";
|
||||
Object insertNewRole = dbSource.WriteData(sqlUser);
|
||||
// Create string for confirming user account
|
||||
string confirmUser = $"Select * from users where username = {newUser.NewUserName} " +
|
||||
$"and password = {newUser.NewPassword};";
|
||||
Object conUser = dbSource.ReadData(confirmUser);
|
||||
string sqlUser = $"UPDATE users t SET t.Password = '{editUser.password}', " +
|
||||
$"t.Role = '{editUser.role}',t.Email = '{editUser.email}' " +
|
||||
$"WHERE t.UserName = '{editUser.username}';";
|
||||
|
||||
//Console.WriteLine("type of Reesult:" + confirmAdmin.GetType());
|
||||
OdbcDataReader reader = null;
|
||||
bool updateNewUser = dbSource.UpdateData(sqlUser);
|
||||
return updateNewUser;
|
||||
|
||||
if (conUser.GetType() == typeof(OdbcDataReader))
|
||||
{
|
||||
reader = (OdbcDataReader)conUser;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool DeleteUserRecord(UserAccount deleteUser, string CreatedBy, IDataSource<string> dbSource)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Insert into users table
|
||||
string sqlUser = $"DELETE from users WHERE UserName = '{deleteUser.username}' " +
|
||||
$"and Password = '{deleteUser.password}';";
|
||||
|
||||
// Read Sql query results
|
||||
while (reader.Read())
|
||||
{
|
||||
Console.WriteLine(reader.GetString(0));
|
||||
}
|
||||
bool deleteNewUser = dbSource.DeleteData(sqlUser);
|
||||
return deleteNewUser;
|
||||
|
||||
SqlDAO sqlDS = (SqlDAO)dbSource;
|
||||
Console.WriteLine("");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool DisableUser(UserAccount disableUser, string CreatedBy, IDataSource<string> dbSource)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Insert into users table
|
||||
string sqlUser = $"UPDATE users u SET u.IsActive = 0 WHERE u.UserName = '{disableUser.username}'" +
|
||||
$"and u.Role = '{disableUser.role}';";
|
||||
|
||||
bool disableNewUser = dbSource.UpdateData(sqlUser);
|
||||
return disableNewUser;
|
||||
|
||||
// Closing the connection
|
||||
sqlDS.getConnection().Close();*/
|
||||
return true;
|
||||
}
|
||||
public bool DeleteUserRecord(UserAccount newUser, IDataSource<string> dbSource)
|
||||
catch (Exception ex)
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public bool DisableUser(UserAccount newUser, IDataSource<string> dbSource)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public bool EnableUser(UserAccount newUser, IDataSource<string> dbSource)
|
||||
public bool EnableUser(UserAccount enableUser, string CreatedBy, IDataSource<string> dbSource)
|
||||
{
|
||||
return true;
|
||||
try
|
||||
{
|
||||
// Insert into users table
|
||||
string sqlUser = $"UPDATE users u SET u.IsActive = 1 WHERE u.UserName = '{enableUser.username}'" +
|
||||
$"and u.Role = '{enableUser.role}';";
|
||||
|
||||
bool disableNewUser = dbSource.UpdateData(sqlUser);
|
||||
return disableNewUser;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,10 +171,11 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
Console.WriteLine("");
|
||||
|
||||
// Closing the connection
|
||||
sqlDS.getConnection().Close();
|
||||
sqlDS.GetConnection().Close();
|
||||
|
||||
if (checkSql == "Admin")
|
||||
{
|
||||
Console.WriteLine("-- Logged in successfully.");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -204,12 +205,12 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
AccountService accountService = new AccountService();
|
||||
// Create credentials object for new inptus
|
||||
GetCredentials newCredentials = new GetCredentials();
|
||||
// Print User Management menu
|
||||
ui.UserManagementMenu(user.username);
|
||||
// Create bool object for menu loop
|
||||
bool menuLoop = true;
|
||||
// Create loop for menu
|
||||
while (menuLoop is true) {
|
||||
// Print User Management menu
|
||||
ui.UserManagementMenu(user.username);
|
||||
// Get user choice
|
||||
int menuChoice = Convert.ToInt32(Console.ReadLine());
|
||||
// Complete the appropriate action
|
||||
@ -217,38 +218,91 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
{
|
||||
// Exit menu
|
||||
case 0:
|
||||
return "Exiting UserManagement.\n";
|
||||
break;
|
||||
return "Back to Login";
|
||||
// Create account
|
||||
case 1:
|
||||
// Get all credentials and create newUser
|
||||
UserAccount newUser = new UserAccount(newCredentials.GetUserName(),
|
||||
newCredentials.GetPassword(), newCredentials.GetEmail(),
|
||||
newCredentials.ConfirmPassword(), newCredentials.GetEmail(),
|
||||
newCredentials.GetRole(), DateTime.UtcNow);
|
||||
accountService.CreateUserRecord(newUser,user.username, dbSource);
|
||||
bool accountValid = accountService.CreateUserRecord(newUser, user.username, dbSource);
|
||||
if (accountValid is true)
|
||||
{
|
||||
Console.WriteLine("\nAccount created Successfully");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Database Timed out";
|
||||
}
|
||||
// Edit account
|
||||
case 2:
|
||||
/* UserAccount newEditUser = new UserAccount(newCredentials.GetUserName(),
|
||||
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||
accountService.EditUserRecord(newEditUser, dbSource);*/
|
||||
// State what account is being edited
|
||||
string userName = newCredentials.GetUserName();
|
||||
string userRole = newCredentials.GetRole();
|
||||
|
||||
// Notify the user of what can be edited
|
||||
Console.WriteLine($"\n****The following information will be used to update {userName}");
|
||||
|
||||
// Get updated parameters
|
||||
UserAccount newEditUser = new UserAccount(userName,
|
||||
newCredentials.GetPassword(), newCredentials.GetEmail(),
|
||||
newCredentials.GetRole(), DateTime.UtcNow);
|
||||
bool editValid = accountService.EditUserRecord(newEditUser, user.username, dbSource);
|
||||
if (editValid is true)
|
||||
{
|
||||
Console.WriteLine("\nAccount updated Successfully");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Database Timed out";
|
||||
}
|
||||
break;
|
||||
// Delete account
|
||||
case 3:
|
||||
UserAccount newDeleteUser = new UserAccount(newCredentials.GetUserName(),
|
||||
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||
accountService.DeleteUserRecord(newDeleteUser, dbSource);
|
||||
bool deleteValid = accountService.DeleteUserRecord(newDeleteUser, user.username , dbSource);
|
||||
if (deleteValid is true)
|
||||
{
|
||||
Console.WriteLine("\nAccount deleted Successfully");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "User does not exist";
|
||||
}
|
||||
break;
|
||||
// Disable account
|
||||
case 4:
|
||||
UserAccount newDisableUser = new UserAccount(newCredentials.GetUserName(),
|
||||
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||
accountService.DisableUser(newDisableUser, dbSource);
|
||||
newCredentials.GetRole());
|
||||
bool disableValid = accountService.DisableUser(newDisableUser, user.username , dbSource);
|
||||
if (disableValid is true)
|
||||
{
|
||||
Console.WriteLine("\nAccount disabled Successfully");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Database Timed out";
|
||||
}
|
||||
break;
|
||||
// Enable account
|
||||
case 5:
|
||||
UserAccount newEnableUser = new UserAccount(newCredentials.GetUserName(),
|
||||
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||
accountService.EnableUser(newEnableUser, dbSource);
|
||||
newCredentials.GetRole());
|
||||
bool enableValid = accountService.EnableUser(newEnableUser, user.username , dbSource);
|
||||
if (enableValid is true)
|
||||
{
|
||||
Console.WriteLine("\nAccount enabled Successfully");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Database Timed out";
|
||||
}
|
||||
break;
|
||||
// View logs
|
||||
case 6:
|
||||
@ -261,9 +315,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string dbAction = user.username;
|
||||
return dbAction;
|
||||
return "Back to Login";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
{
|
||||
{ // Class for getting user credentials
|
||||
public class GetCredentials
|
||||
{
|
||||
public string? GetUserName()
|
||||
@ -20,11 +20,26 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
string? userPassword = Console.ReadLine();
|
||||
return userPassword;
|
||||
}
|
||||
/*public string ConfirmPassword()
|
||||
public string ConfirmPassword()
|
||||
{
|
||||
Console.WriteLine();
|
||||
string confirmPassword = newUser.NewPassword;
|
||||
}*/
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine("Please enter a password:");
|
||||
string? userPassword = Console.ReadLine();
|
||||
// Confirm Password
|
||||
Console.WriteLine("Please re-enter the password:");
|
||||
string checkPsswd = Console.ReadLine();
|
||||
// Check if passwords match
|
||||
if (userPassword == checkPsswd)
|
||||
{
|
||||
return userPassword;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Passwords do not match.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
public string GetEmail()
|
||||
{
|
||||
Console.WriteLine("Please enter an email:");
|
||||
@ -52,6 +67,12 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||
_password = pwd;
|
||||
_Time = TimeStamp;
|
||||
}
|
||||
public UserAccount(string un, string role)
|
||||
{
|
||||
_userName = un;
|
||||
_Role = role;
|
||||
_Time = DateTime.UtcNow;
|
||||
}
|
||||
public UserAccount(string newUN, string newPWD, string Email, string role, DateTime newTime)
|
||||
{
|
||||
_userName = newUN;
|
||||
|
||||
@ -3,6 +3,11 @@ 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.UserManagement.Tests", "..\TeamHobby.UserManagement.Tests\TeamHobby.UserManagement.Tests.csproj", "{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F} = {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}
|
||||
{2E7193B8-86B6-48DA-9671-CD84615A5F5D} = {2E7193B8-86B6-48DA-9671-CD84615A5F5D}
|
||||
EndProjectSection
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Models", "..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj", "{75DED6C2-D404-4E71-A58B-0F616DB5C062}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "main", "..\main\main.csproj", "{30C7EBF3-3957-46E5-86C1-C13356841ECA}"
|
||||
@ -15,6 +20,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGener
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.UserManagement", "..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj", "{2E7193B8-86B6-48DA-9671-CD84615A5F5D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Logging.Tests", "..\TeamHobby.HobbyProjectGenerator.Logging.Tests\TeamHobby.HobbyProjectGenerator.Logging.Tests.csproj", "{CA8D11CF-807C-4C90-A529-0371F73518F6}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.ArchiveTests", "..\TeamHobby.HobbyProjectGenerator.ArchiveTests\TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj", "{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.UserManagement.xTests", "TeamHobby.UserManagement.xTests\TeamHobby.UserManagement.xTests.csproj", "{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D29D9225-3748-4067-AF07-E677A525EF39}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
TeamHobby.HobbyProjectGenerator.csproj = TeamHobby.HobbyProjectGenerator.csproj
|
||||
EndProjectSection
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.ArchiveTests", "..\TeamHobby.HobbyProjectGenerator.ArchiveTests\TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj", "{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}"
|
||||
EndProject
|
||||
Global
|
||||
@ -23,6 +38,12 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|x86.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
|
||||
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|x86.Build.0 = Release|Any CPU
|
||||
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@ -32,6 +53,8 @@ Global
|
||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
@ -40,6 +63,8 @@ Global
|
||||
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
@ -48,9 +73,19 @@ Global
|
||||
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{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}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|x86.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
|
||||
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|x86.Build.0 = Release|Any CPU
|
||||
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,13 @@
|
||||
using Xunit;
|
||||
|
||||
namespace TeamHobby.UserManagement.xTests
|
||||
{
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,28 +2,10 @@
|
||||
using System.Data.Odbc;
|
||||
using TeamHobby.HobbyProjectGenerator.Archive;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||
using TeamHobby.HobbyProjectGenerator.Logging;
|
||||
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.Main
|
||||
{
|
||||
|
||||
public class GetCredentials
|
||||
{
|
||||
|
||||
public string? GetUserName()
|
||||
{
|
||||
Console.WriteLine("Please enter a username:");
|
||||
string? userName = Console.ReadLine();
|
||||
return userName;
|
||||
}
|
||||
public string? GetPassword()
|
||||
{
|
||||
Console.WriteLine("Please enter " +
|
||||
"a password:");
|
||||
string? userPassword = Console.ReadLine();
|
||||
return userPassword;
|
||||
}
|
||||
public class Controller
|
||||
{
|
||||
|
||||
@ -37,27 +19,37 @@ 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();
|
||||
//GetCredentials credentials = new GetCredentials();
|
||||
//string? username = credentials.GetUserName();
|
||||
//string? password = credentials.GetPassword();
|
||||
// Console customization
|
||||
// Change the look of the console
|
||||
Console.Title = "HobbyProjectGenerator";
|
||||
// Change console text color
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
// Change terminal height
|
||||
Console.WindowHeight = 40;
|
||||
//Console.WriteLine(value: $"username is {username}\npassword is {password}");
|
||||
|
||||
// Creating the Factory class
|
||||
// Creating the Factory class
|
||||
// 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 " +
|
||||
"or enter 0 to exit the machine\n");
|
||||
string? username = credentials.GetUserName();
|
||||
//int menuExit = Convert.ToInt32(username);
|
||||
// Exit Infinite Menu
|
||||
if (username == "0")
|
||||
{
|
||||
break;
|
||||
}
|
||||
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
|
||||
@ -68,69 +60,41 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = factory.getDataSource(dbType, dbInfo);
|
||||
"PORT=3306;";
|
||||
|
||||
|
||||
"OPTION=3";
|
||||
|
||||
IDataSource<string> 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));
|
||||
string isLogin = manager.CreateUserRecord(user, datasource);
|
||||
|
||||
//Console.WriteLine(value: $"Welcome {username}\n");
|
||||
|
||||
/* string sqlQuery = "Select * from log;";
|
||||
Object result = datasource.ReadData(sqlQuery);
|
||||
Console.WriteLine("type of Result: " + result.GetType());
|
||||
OdbcDataReader reader = null;
|
||||
|
||||
if (result.GetType() == typeof(OdbcDataReader))
|
||||
if (isLogin != "Access Denied: Unauthorized\n")
|
||||
{
|
||||
reader = (OdbcDataReader)result;
|
||||
Console.WriteLine("Returning to login...\n");
|
||||
Console.WriteLine("-------------------------------------\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("******Access Denied: Unauthorized******");
|
||||
}
|
||||
|
||||
}
|
||||
// [Logname, loglevel, date, time, ...]
|
||||
|
||||
Console.WriteLine("Reading from the database");
|
||||
while (reader.Read())
|
||||
{
|
||||
Console.WriteLine("Date={0} {1} {2} {3} {4} {5}", reader[0], reader[1], reader[2], reader[3], reader[4], reader[5]);
|
||||
}
|
||||
SqlDAO sqlDS = (SqlDAO)datasource;
|
||||
Console.WriteLine("");
|
||||
|
||||
// Closing the connection
|
||||
sqlDS.GetConnection().Close();
|
||||
|
||||
// While loop to keep this running forever with UserManagement
|
||||
//Testing archive Manager
|
||||
/* // While loop to keep this running forever with UserManagement
|
||||
// Testing archive Manager
|
||||
//while (true)
|
||||
//{
|
||||
//string currentDate = DateTime.Now.ToString("dd");
|
||||
//string currentTime = DateTime.Now.ToString("T");
|
||||
//string activateDate = "01";
|
||||
//string activateTime = "00:00:00 AM";
|
||||
//Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
||||
//if (String.Equals(currentDate, activateDate) && String.Equals(currentTime, activateTime))
|
||||
//{
|
||||
//ArchiveManager archive = new ArchiveManager(datasource);
|
||||
//archive.Controller();
|
||||
//}
|
||||
//}
|
||||
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();
|
||||
}
|
||||
//}*/
|
||||
|
||||
|
||||
|
||||
@ -178,83 +142,6 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
||||
//Console.WriteLine("Writing to the database... ");
|
||||
//datasource.WriteData(sqlRemove);
|
||||
//Console.WriteLine("Writing completed. ");
|
||||
|
||||
/* 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;
|
||||
|
||||
|
||||
// Create class objects
|
||||
UiPrint menu = new UiPrint();
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
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
|
||||
|
||||
|
||||
// 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;
|
||||
};*/
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
|
||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Logging\TeamHobby.HobbyProjectGenerator.Logging.csproj" />
|
||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj" />
|
||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@ -1,26 +1,5 @@
|
||||
create table users
|
||||
(
|
||||
UserName varchar(50) charset utf8mb3 not null,
|
||||
Password varchar(50) charset utf8mb3 not null,
|
||||
Role varchar(50) charset utf8mb3 not null,
|
||||
IsActive int default 1 not null,
|
||||
CreatedBy varchar(50) charset utf8mb3 not null,
|
||||
CreatedDate datetime not null,
|
||||
constraint userRole_fk foreign key (Role) references roles (Role),
|
||||
constraint user_pk primary key (UserName)
|
||||
);
|
||||
|
||||
INSERT INTO hobby.users (UserName, Password, Role, IsActive, CreatedBy, CreatedDate, Email) VALUES
|
||||
('Colin ', 'Waffle', 'Admin', 1, 'Jacob', '2021-12-13 04:27:42', null),
|
||||
('Danny', 'Spartan', 'Admin', 1, 'Jacob', '2021-12-13 04:29:54', null),
|
||||
('Jacob', 'Teamhobby1234', 'Admin', 1, 'SystemCreator', '2021-12-13 03:25:14', null),
|
||||
('Long', 'Joystick', 'regular', 1, 'Jacob', '2021-12-13 04:29:57', null),
|
||||
('Rifat', 'ApproveDar', 'Admin', 1, 'Jacob', '2021-12-13 04:29:55', null);
|
||||
|
||||
|
||||
create table roles
|
||||
(
|
||||
RoleID int not null,
|
||||
Role varchar(50) charset utf8mb3 not null,
|
||||
CreatedBy varchar(200) charset utf8mb3 not null,
|
||||
CreatedDate datetime not null,
|
||||
@ -28,6 +7,31 @@ create table roles
|
||||
primary key (Role)
|
||||
);
|
||||
|
||||
create table users
|
||||
(
|
||||
UserName varchar(50) charset utf8mb3 not null
|
||||
primary key,
|
||||
Password varchar(50) charset utf8mb3 not null,
|
||||
Role varchar(50) charset utf8mb3 not null,
|
||||
IsActive int default 1 not null,
|
||||
CreatedBy varchar(50) charset utf8mb3 not null,
|
||||
CreatedDate datetime not null,
|
||||
Email varchar(50) null,
|
||||
constraint users_Email_uindex
|
||||
unique (Email),
|
||||
constraint userRole_fk
|
||||
foreign key (Role) references roles (Role)
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO hobby.users (UserName, Password, Role, IsActive, CreatedBy, CreatedDate, Email) VALUES
|
||||
('Colin ', 'Waffle', 'Admin', 1, 'Jacob', '2021-12-13 04:27:42', null),
|
||||
('Danny', 'Spartan', 'Admin', 1, 'Jacob', '2021-12-13 04:29:54', null),
|
||||
('Jacob', 'Teamhobby1234', 'Admin', 1, 'SystemCreator', '2021-12-13 03:25:14', null),
|
||||
('Long', 'Joystick', 'regular', 1, 'Jacob', '2021-12-13 04:29:57', null),
|
||||
('Rifat', '1234', 'Admin', 1, 'Jacob', '2021-12-13 04:29:55', null);
|
||||
|
||||
|
||||
INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES
|
||||
('Admin', 'Jacob', '2021-12-13 03:25:14'),
|
||||
('regular', 'Colin', '2021-12-13 03:25:14');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user