commit
5224841dac
26
Source Code/.vscode/launch.json
vendored
Normal file
26
Source Code/.vscode/launch.json
vendored
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
42
Source Code/.vscode/tasks.json
vendored
Normal file
42
Source Code/.vscode/tasks.json
vendored
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -17,9 +17,9 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
|||||||
public SqlDAO(string info)
|
public SqlDAO(string info)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Console.WriteLine("Establising Connection");
|
Console.WriteLine("Establising Connection...");
|
||||||
_conn = new OdbcConnection(info);
|
_conn = new OdbcConnection(info);
|
||||||
Console.WriteLine("Connection established");
|
Console.WriteLine("Connection established.");
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
//_conn = null;
|
//_conn = null;
|
||||||
|
|||||||
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,10 +3,79 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Data.Odbc;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||||
{
|
{
|
||||||
internal class AccountService
|
public class AccountService
|
||||||
{
|
{
|
||||||
|
public bool CreateUserRecord(UserAccount newUser, string CreatedBy, IDataSource<string> dbSource)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Insert into users table
|
||||||
|
string sqlUser = $"INSERT INTO users (UserName, Password, Role, IsActive," +
|
||||||
|
$"CreatedBy, CreatedDate, Email) VALUES ('{newUser.username}', " +
|
||||||
|
$"'{newUser.password}','{newUser.role}', 1," +
|
||||||
|
$"'{CreatedBy}', NOW(),'{newUser.email}');";
|
||||||
|
|
||||||
|
bool insertNewUser = dbSource.WriteData(sqlUser);
|
||||||
|
return insertNewUser;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool EditUserRecord(UserAccount newUser, string CreatedBy, IDataSource<string> dbSource)
|
||||||
|
{
|
||||||
|
/* // Insert into users table
|
||||||
|
string sqlUser = $"UPDATE hobby.roles r SET r.Role = 'regular',r.CreatedBy = 'colin'WHERE r.RoleID = 5; ";
|
||||||
|
|
||||||
|
Object insertNewUser = dbSource.WriteData(sqlUser);
|
||||||
|
// Insert into users table
|
||||||
|
string sqlRoles = $"INSERT INTO roles (Role, CreatedBy, CreatedDate) " +
|
||||||
|
$"VALUES ('{newUser.NewRole}', '{CreatedBy}', NOW());";
|
||||||
|
Object insertNewRole = dbSource.WriteData(sqlUser);
|
||||||
|
// Create string for confirming user account
|
||||||
|
string confirmUser = $"Select * from users where username = {newUser.NewUserName} " +
|
||||||
|
$"and password = {newUser.NewPassword};";
|
||||||
|
Object conUser = dbSource.ReadData(confirmUser);
|
||||||
|
|
||||||
|
//Console.WriteLine("type of Reesult:" + confirmAdmin.GetType());
|
||||||
|
OdbcDataReader reader = null;
|
||||||
|
|
||||||
|
if (conUser.GetType() == typeof(OdbcDataReader))
|
||||||
|
{
|
||||||
|
reader = (OdbcDataReader)conUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read Sql query results
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
Console.WriteLine(reader.GetString(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
SqlDAO sqlDS = (SqlDAO)dbSource;
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
// Closing the connection
|
||||||
|
sqlDS.getConnection().Close();*/
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool DeleteUserRecord(UserAccount newUser, IDataSource<string> dbSource)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool DisableUser(UserAccount newUser, IDataSource<string> dbSource)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool EnableUser(UserAccount newUser, IDataSource<string> dbSource)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,9 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Data.Odbc;
|
||||||
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
||||||
using TeamHobby.HobbyProjectGenerator.Implementations;
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||||
{
|
{
|
||||||
@ -13,125 +14,257 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
|||||||
public string IsInputValid(string checkUN, string checkPWD)
|
public string IsInputValid(string checkUN, string checkPWD)
|
||||||
{
|
{
|
||||||
// Create bool variables to check if username and password are valid
|
// 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 == '!');
|
|| 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)
|
if (checkUN == null || checkPWD == null)
|
||||||
{
|
{
|
||||||
return "Invalid input\n";
|
return "Invalid input\n";
|
||||||
}
|
}
|
||||||
|
// Check if username is within the restricted length
|
||||||
else if (checkUN.Length > 15 || checkUN.Length <= 0
|
else if (checkUN.Length > 15 || checkUN.Length <= 0
|
||||||
|| ValidUN is false)
|
|| validUN is false)
|
||||||
{
|
{
|
||||||
return "Invalid Username\n";
|
return "Invalid Username\n";
|
||||||
}
|
}
|
||||||
|
// Check if password is within the restricted length
|
||||||
else if (checkPWD.Length > 18 || checkPWD.Length <= 0
|
else if (checkPWD.Length > 18 || checkPWD.Length <= 0
|
||||||
|| ValidPwd is false)
|
|| validPwd is false)
|
||||||
{
|
{
|
||||||
return "Invalid Password\n";
|
return "Invalid Password\n";
|
||||||
}
|
}
|
||||||
|
// Check if username and password are valid
|
||||||
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
||||||
|| ValidUN is true && checkPWD.Length <= 18
|
&& validUN is true && checkPWD.Length <= 18
|
||||||
&& checkPWD.Length > 0 || ValidPwd is true)
|
&& checkPWD.Length > 0 && validPwd is true)
|
||||||
{
|
{
|
||||||
return "Username and password is valid.\n";
|
return "Username and password is valid.\n";
|
||||||
}
|
}
|
||||||
|
// Check if username and password and email are valid
|
||||||
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
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";
|
return "Valid Username\n";
|
||||||
}
|
}
|
||||||
|
// For testing to make sure password is valid
|
||||||
else if (checkPWD.Length <= 18 && checkPWD.Length > 0
|
else if (checkPWD.Length <= 18 && checkPWD.Length > 0
|
||||||
|| ValidPwd is true)
|
&& validPwd is true)
|
||||||
{
|
{
|
||||||
return "Valid Password\n";
|
return "Valid Password\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return "Invalid Input\n";
|
return "Invalid input\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public bool isAdmin()
|
public string IsInputValid(string checkUN, string checkPWD, string email, string role)
|
||||||
|
{
|
||||||
|
// Create bool variables to check if username and password and email are valid
|
||||||
|
bool validUN = checkUN.All(un => Char.IsLetterOrDigit(un) || un == '@'
|
||||||
|
|| un == '.' || un == ',' || un == '!');
|
||||||
|
|
||||||
|
bool validPwd = checkPWD.All(Char.IsLetterOrDigit);
|
||||||
|
|
||||||
|
bool validEmail = email.All(email => Char.IsLetterOrDigit(email) && email == '@'
|
||||||
|
&& email == '.');
|
||||||
|
|
||||||
|
bool validRole = role.All(role => Char.IsLetter(role));
|
||||||
|
|
||||||
|
// Check if any are empty
|
||||||
|
if (checkUN == null || checkPWD == null || email == null)
|
||||||
|
{
|
||||||
|
return "Invalid input\n";
|
||||||
|
}
|
||||||
|
// Check if username is within the restricted length
|
||||||
|
else if (checkUN.Length > 15 || checkUN.Length <= 0
|
||||||
|
|| validUN is false)
|
||||||
|
{
|
||||||
|
return "Invalid Username\n";
|
||||||
|
}
|
||||||
|
// Check if password is within the restricted length
|
||||||
|
else if (checkPWD.Length > 18 || checkPWD.Length <= 0
|
||||||
|
|| validPwd is false)
|
||||||
|
{
|
||||||
|
return "Invalid Password\n";
|
||||||
|
}
|
||||||
|
// Check if email is within the restricted length
|
||||||
|
else if (email.Length > 18 || email.Length <= 0
|
||||||
|
|| validEmail is false)
|
||||||
|
{
|
||||||
|
return "Invalid Email.\n";
|
||||||
|
}
|
||||||
|
// Check if username and password are valid
|
||||||
|
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
||||||
|
&& validUN is true && checkPWD.Length <= 18
|
||||||
|
&& checkPWD.Length > 0 && validPwd is true)
|
||||||
|
{
|
||||||
|
return "Username and password is valid.\n";
|
||||||
|
}
|
||||||
|
// Check if username and password and email are valid
|
||||||
|
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
||||||
|
&& validUN is true && checkPWD.Length <= 18
|
||||||
|
&& checkPWD.Length > 0 && validPwd is true
|
||||||
|
&& email.Length > 18 && email.Length <= 0
|
||||||
|
&& validEmail is true)
|
||||||
|
{
|
||||||
|
return "Username and password is valid.\n";
|
||||||
|
}
|
||||||
|
// For testing to make sure username is valid
|
||||||
|
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
||||||
|
&& validUN is true)
|
||||||
|
{
|
||||||
|
return "Valid Username\n";
|
||||||
|
}
|
||||||
|
// For testing to make sure password is valid
|
||||||
|
else if (checkPWD.Length <= 18 && checkPWD.Length > 0
|
||||||
|
&& validPwd is true)
|
||||||
|
{
|
||||||
|
return "Valid Password\n";
|
||||||
|
}
|
||||||
|
// For testing to make sure email is valid
|
||||||
|
else if (email.Length > 18 && email.Length <= 0
|
||||||
|
&& validEmail is true)
|
||||||
|
{
|
||||||
|
return "Valid Password\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "Invalid input\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check with database if user is an admin
|
||||||
|
public bool isAdmin(UserAccount user, IDataSource<string> dbSource)
|
||||||
|
{
|
||||||
|
// string checkAdmin = $"Select * from users where username = {user.username} and password = {user.password};";
|
||||||
|
string checkAdmin = $"select r.Role from roles r, users u where " +
|
||||||
|
$"UserName = '{user.username}' and Password = '{user.password}' and r.Role = u.Role;";
|
||||||
|
Object confirmAdmin = dbSource.ReadData(checkAdmin);
|
||||||
|
//Console.WriteLine("type of Reesult:" + confirmAdmin.GetType());
|
||||||
|
OdbcDataReader reader = null;
|
||||||
|
|
||||||
|
if (confirmAdmin.GetType() == typeof(OdbcDataReader))
|
||||||
|
{
|
||||||
|
reader = (OdbcDataReader)confirmAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create String to hold sql output
|
||||||
|
string checkSql = "";
|
||||||
|
|
||||||
|
// Read Sql query results
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
checkSql = reader.GetString(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SqlDAO sqlDS = (SqlDAO)dbSource;
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
// Closing the connection
|
||||||
|
sqlDS.getConnection().Close();
|
||||||
|
|
||||||
|
if (checkSql == "Admin")
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public void CreateUserRecord(UserAccount user)
|
|
||||||
{
|
|
||||||
Console.Write(IsInputValid(user.username, user.password));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public string CreateUserRecord(UserAccount user, IDataSource<string> dbSource)
|
||||||
|
|
||||||
|
|
||||||
/*public NewUserName()
|
|
||||||
{
|
{
|
||||||
|
// Check Login inputs
|
||||||
|
IsInputValid(user.username, user.password);
|
||||||
|
|
||||||
}
|
bool Admin = isAdmin(user, dbSource);
|
||||||
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
|
// Give access if the user is and Admin
|
||||||
//int userCreateConfirm = new CreateUser(userName,userPassword,SecQuest,SecAnswer);
|
if (Admin is false)
|
||||||
|
|
||||||
// Check if user creation was successful
|
|
||||||
/*if (userCreateConfirm = 1)
|
|
||||||
{
|
{
|
||||||
|
return "Access Denied: Unauthorized\n";
|
||||||
// Confirm to user that the account has been created
|
|
||||||
Console.WriteLine("Account created succesfully with the username of" + userName);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// db.users layout (UserName, Password, RoleID, IsActive, CreatedBy, CreatedDate)
|
||||||
}*/
|
// db.roles layout (RoleID(AutoGen), Role, CreatedBy, CreatedDate)
|
||||||
/*conPsswrd = false;
|
// Create UiPrint Object
|
||||||
}
|
|
||||||
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();
|
UiPrint ui = new UiPrint();
|
||||||
|
// Create Account Service object
|
||||||
bool foo = true;
|
AccountService accountService = new AccountService();
|
||||||
|
// Create credentials object for new inptus
|
||||||
while (foo == true)
|
GetCredentials newCredentials = new GetCredentials();
|
||||||
|
// Print User Management menu
|
||||||
|
ui.UserManagementMenu(user.username);
|
||||||
|
// Create bool object for menu loop
|
||||||
|
bool menuLoop = true;
|
||||||
|
// Create loop for menu
|
||||||
|
while (menuLoop is true) {
|
||||||
|
// Get user choice
|
||||||
|
int menuChoice = Convert.ToInt32(Console.ReadLine());
|
||||||
|
// Complete the appropriate action
|
||||||
|
switch (menuChoice)
|
||||||
{
|
{
|
||||||
// sub menu
|
// Exit menu
|
||||||
ui.SystemAccountMenu();
|
case 0:
|
||||||
//
|
return "Exiting UserManagement.\n";
|
||||||
|
break;
|
||||||
}
|
// Create account
|
||||||
|
case 1:
|
||||||
|
UserAccount newUser = new UserAccount(newCredentials.GetUserName(),
|
||||||
|
newCredentials.GetPassword(), newCredentials.GetEmail(),
|
||||||
|
newCredentials.GetRole(), DateTime.UtcNow);
|
||||||
|
accountService.CreateUserRecord(newUser,user.username, dbSource);
|
||||||
|
break;
|
||||||
|
// Edit account
|
||||||
|
case 2:
|
||||||
|
/* UserAccount newEditUser = new UserAccount(newCredentials.GetUserName(),
|
||||||
|
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||||
|
accountService.EditUserRecord(newEditUser, dbSource);*/
|
||||||
|
break;
|
||||||
|
// Delete account
|
||||||
|
case 3:
|
||||||
|
UserAccount newDeleteUser = new UserAccount(newCredentials.GetUserName(),
|
||||||
|
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||||
|
accountService.DeleteUserRecord(newDeleteUser, dbSource);
|
||||||
|
break;
|
||||||
|
// Disable account
|
||||||
|
case 4:
|
||||||
|
UserAccount newDisableUser = new UserAccount(newCredentials.GetUserName(),
|
||||||
|
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||||
|
accountService.DisableUser(newDisableUser, dbSource);
|
||||||
|
break;
|
||||||
|
// Enable account
|
||||||
|
case 5:
|
||||||
|
UserAccount newEnableUser = new UserAccount(newCredentials.GetUserName(),
|
||||||
|
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||||
|
accountService.EnableUser(newEnableUser, dbSource);
|
||||||
|
break;
|
||||||
|
// View logs
|
||||||
|
case 6:
|
||||||
|
break;
|
||||||
|
// View archive
|
||||||
|
case 7:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Console.WriteLine("Invalid input.\nPlease enter a valid option.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string dbAction = user.username;
|
||||||
|
return dbAction;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator\TeamHobby.HobbyProjectGenerator.csproj" />
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -6,37 +6,70 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
namespace TeamHobby.HobbyProjectGenerator.UserManagement
|
||||||
{
|
{
|
||||||
|
public class GetCredentials
|
||||||
|
{
|
||||||
|
public string? GetUserName()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please enter a username:");
|
||||||
|
string? userName = Console.ReadLine();
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
public string? GetPassword()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please enter a password:");
|
||||||
|
string? userPassword = Console.ReadLine();
|
||||||
|
return userPassword;
|
||||||
|
}
|
||||||
|
/*public string ConfirmPassword()
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
string confirmPassword = newUser.NewPassword;
|
||||||
|
}*/
|
||||||
|
public string GetEmail()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please enter an email:");
|
||||||
|
return Console.ReadLine();
|
||||||
|
}
|
||||||
|
public string GetRole()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please enter the role of the user:");
|
||||||
|
return Console.ReadLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
public class UserAccount
|
public class UserAccount
|
||||||
{
|
{
|
||||||
// Admin Credentials
|
// Admin Credentials
|
||||||
private string UserName;
|
private string _userName;
|
||||||
private string Password;
|
private string _password;
|
||||||
private DateTime Time;
|
private DateTime _Time;
|
||||||
|
// New User Credentials
|
||||||
|
private string _Email;
|
||||||
|
private string _Role;
|
||||||
|
|
||||||
public UserAccount(string un, string pwd, DateTime TimeStamp)
|
public UserAccount(string un, string pwd, DateTime TimeStamp)
|
||||||
{
|
{
|
||||||
UserName = un;
|
_userName = un;
|
||||||
Password = pwd;
|
_password = pwd;
|
||||||
Time = TimeStamp;
|
_Time = TimeStamp;
|
||||||
}
|
}
|
||||||
public string username { get { return UserName; } }
|
public UserAccount(string newUN, string newPWD, string Email, string role, DateTime newTime)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
newusername = newUN;
|
_userName = newUN;
|
||||||
newpassword = newPWD;
|
_password = newPWD;
|
||||||
newemail = Email;
|
_Role = role;
|
||||||
newtime = newTime;
|
_Email = Email;
|
||||||
|
_Time = newTime;
|
||||||
}
|
}
|
||||||
public string NewUserName { get { return newusername; } }
|
public UserAccount()
|
||||||
public string NewPassword { get { return newpassword; } }
|
{
|
||||||
public string NewEmail { get { return newemail; } }
|
_Role = "regular";
|
||||||
public DateTime Newtime { get { return newtime; } }
|
_Time= DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string username { get { return _userName; } }
|
||||||
|
public string password { get { return _password; } }
|
||||||
|
public string email { get { return _Email; } }
|
||||||
|
public string role { get { return _Role; } }
|
||||||
|
public DateTime Time { get { return _Time; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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<string> _logstore;
|
|
||||||
|
|
||||||
public InMemoryUserService()
|
|
||||||
{
|
|
||||||
_logstore = new List<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IList<string> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
||||||
|
|
||||||
// Print Statements used throughout the program.
|
// Print Statements used throughout the program.
|
||||||
|
|
||||||
@ -21,12 +22,16 @@ namespace TeamHobby.HobbyProjectGenerator
|
|||||||
}
|
}
|
||||||
public void SystemAccountMenu()
|
public void SystemAccountMenu()
|
||||||
{
|
{
|
||||||
// Create intial menu
|
UserAccount user = new UserAccount();
|
||||||
Console.WriteLine("What would you like to do?");
|
// Menu for all UserManagement options
|
||||||
int num = 1;
|
int menu = 0;
|
||||||
Console.WriteLine(num + ".Create a new account.");
|
Console.WriteLine($"Welcome {user.username} to User Management.\n");
|
||||||
num += 1;
|
Console.WriteLine("What would you like to do?\n");
|
||||||
Console.WriteLine(num + ".Access Admin Features");
|
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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
namespace TeamHobby.HobbyProjectGenerator
|
|
||||||
{
|
|
||||||
public class User_Authentication
|
|
||||||
{
|
|
||||||
public IList<string> GetAllUsers()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool User(string username)
|
|
||||||
{
|
|
||||||
//Console.WriteLine("Hello World!");
|
|
||||||
//Console.WriteLine("Testing console");
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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<string> GetAllUsers()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool User(string username)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.0.31919.166
|
VisualStudioVersion = 17.0.31919.166
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
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}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.UserManagement.Tests", "..\TeamHobby.UserManagement.Tests\TeamHobby.UserManagement.Tests.csproj", "{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Models", "..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj", "{75DED6C2-D404-4E71-A58B-0F616DB5C062}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Models", "..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj", "{75DED6C2-D404-4E71-A58B-0F616DB5C062}"
|
||||||
|
|||||||
@ -14,8 +14,4 @@
|
|||||||
<PackageReference Include="coverlet.collector" Version="3.1.0" />
|
<PackageReference Include="coverlet.collector" Version="3.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator\TeamHobby.HobbyProjectGenerator.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -21,12 +21,22 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
|||||||
"a password:");
|
"a password:");
|
||||||
string? userPassword = Console.ReadLine();
|
string? userPassword = Console.ReadLine();
|
||||||
return userPassword;
|
return userPassword;
|
||||||
|
|
||||||
}
|
}
|
||||||
public class Controller
|
public class Controller
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
// Console customization
|
||||||
|
// Change the look of the console
|
||||||
|
Console.Title = "HobbyProjectGenerator";
|
||||||
|
// Change console text color
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
// Change terminal height
|
||||||
|
Console.WindowHeight = 40;
|
||||||
|
|
||||||
|
Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
|
||||||
|
// Creating the Factory class
|
||||||
// Logger log = new Logger();
|
// Logger log = new Logger();
|
||||||
//Logger.PrintTest();
|
//Logger.PrintTest();
|
||||||
//GetCredentials credentials = new GetCredentials();
|
//GetCredentials credentials = new GetCredentials();
|
||||||
@ -49,6 +59,8 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
|||||||
"DATABASE=hobby;" +
|
"DATABASE=hobby;" +
|
||||||
"UID=root;" +
|
"UID=root;" +
|
||||||
"PASSWORD=Teamhobby;" +
|
"PASSWORD=Teamhobby;" +
|
||||||
|
"OPTION=3";
|
||||||
|
IDataSource<string> datasource = factory.getDataSource(dbType, dbInfo);
|
||||||
"PORT=3306;";
|
"PORT=3306;";
|
||||||
|
|
||||||
|
|
||||||
@ -69,7 +81,7 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
|||||||
// Create UserAccount class
|
// Create UserAccount class
|
||||||
UserAccount user = new UserAccount(username, password, TimeStamp);
|
UserAccount user = new UserAccount(username, password, TimeStamp);
|
||||||
|
|
||||||
manager.CreateUserRecord(user);
|
Console.Write(manager.CreateUserRecord(user, datasource));
|
||||||
|
|
||||||
//Console.WriteLine(value: $"Welcome {username}\n");
|
//Console.WriteLine(value: $"Welcome {username}\n");
|
||||||
|
|
||||||
@ -95,18 +107,19 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
|||||||
// Closing the connection
|
// Closing the connection
|
||||||
sqlDS.getConnection().Close();*/
|
sqlDS.getConnection().Close();*/
|
||||||
|
|
||||||
// While loop to keep this running forever with UserManagement
|
/* // While loop to keep this running forever with UserManagement
|
||||||
// Testing archive Manager
|
// Testing archive Manager
|
||||||
//while (true)
|
//while (true)
|
||||||
//{
|
//{
|
||||||
/* string currentDate = DateTime.Now.ToString("dd");
|
string currentDate = DateTime.Now.ToString("dd");
|
||||||
string currentTime = DateTime.Now.ToString("T");
|
string currentTime = DateTime.Now.ToString("T");
|
||||||
Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
||||||
if (String.Equals(currentDate, "1") && String.Equals(currentTime, "00:00:00 AM")){
|
if (String.Equals(currentDate, "1") && String.Equals(currentTime, "00:00:00 AM"))
|
||||||
|
{
|
||||||
ArchiveManager archive = new ArchiveManager(datasource);
|
ArchiveManager archive = new ArchiveManager(datasource);
|
||||||
archive.Controller();
|
archive.Controller();
|
||||||
}*/
|
}
|
||||||
//}
|
//}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Logging\TeamHobby.HobbyProjectGenerator.Logging.csproj" />
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Logging\TeamHobby.HobbyProjectGenerator.Logging.csproj" />
|
||||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj" />
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj" />
|
||||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj" />
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj" />
|
||||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator\TeamHobby.HobbyProjectGenerator.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user