fixed create account sql and edit account

This commit is contained in:
Im_Alpha 2021-12-13 20:09:07 -08:00
parent b2a627a9c7
commit c100a73b39
5 changed files with 125 additions and 111 deletions

26
Source Code/.vscode/launch.json vendored Normal file
View 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
View 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"
}
]
}

View File

@ -10,23 +10,39 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
{ {
public class AccountService public class AccountService
{ {
public bool CreateUserRecord(UserAccount newUser, IDataSource<string> dbSource) public bool CreateUserRecord(UserAccount newUser, string CreatedBy, IDataSource<string> dbSource)
{ {
// string checkAdmin = $"Select * from users where username = {user.username} and password = {user.password};"; try
// Insert into users table {
string sqlUser = $"INSERT INTO hobby.users (UserName, Password," + // Insert into users table
$"CreatedBy, CreatedDate, Email) VALUES ('{newUser.NewUserName}', " + string sqlUser = $"INSERT INTO users (UserName, Password, Role, IsActive," +
$"'{newUser.NewPassword}','{newUser.username}', NOW(),'{newUser.NewEmail}');"; $"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); Object insertNewUser = dbSource.WriteData(sqlUser);
// Insert into users table // Insert into users table
string sqlRoles = $"INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) " + string sqlRoles = $"INSERT INTO roles (Role, CreatedBy, CreatedDate) " +
$"VALUES ('{newUser.NewRole}', '{newUser.username}', NOW());"; $"VALUES ('{newUser.NewRole}', '{CreatedBy}', NOW());";
Object insertNewRole = dbSource.WriteData(sqlUser); Object insertNewRole = dbSource.WriteData(sqlUser);
// Create string for confirming user account // Create string for confirming user account
string confirmUser = $"Select * from users where username = {newUser.NewUserName} " + string confirmUser = $"Select * from users where username = {newUser.NewUserName} " +
$"and password = {newUser.NewPassword};"; $"and password = {newUser.NewPassword};";
Object conUser = dbSource.WriteData(confirmUser); Object conUser = dbSource.ReadData(confirmUser);
//Console.WriteLine("type of Reesult:" + confirmAdmin.GetType()); //Console.WriteLine("type of Reesult:" + confirmAdmin.GetType());
OdbcDataReader reader = null; OdbcDataReader reader = null;
@ -36,9 +52,6 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
reader = (OdbcDataReader)conUser; reader = (OdbcDataReader)conUser;
} }
// Create String to hold sql output
string checkSql = "";
// Read Sql query results // Read Sql query results
while (reader.Read()) while (reader.Read())
{ {
@ -49,11 +62,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
Console.WriteLine(""); Console.WriteLine("");
// Closing the connection // Closing the connection
sqlDS.getConnection().Close(); sqlDS.getConnection().Close();*/
return true;
}
public bool EditUserRecord(UserAccount newUser, IDataSource<string> dbSource)
{
return true; return true;
} }
public bool DeleteUserRecord(UserAccount newUser, IDataSource<string> dbSource) public bool DeleteUserRecord(UserAccount newUser, IDataSource<string> dbSource)

View File

@ -148,7 +148,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
{ {
// string checkAdmin = $"Select * from users where username = {user.username} and password = {user.password};"; // string checkAdmin = $"Select * from users where username = {user.username} and password = {user.password};";
string checkAdmin = $"select r.Role from roles r, users u where " + 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); Object confirmAdmin = dbSource.ReadData(checkAdmin);
//Console.WriteLine("type of Reesult:" + confirmAdmin.GetType()); //Console.WriteLine("type of Reesult:" + confirmAdmin.GetType());
OdbcDataReader reader = null; OdbcDataReader reader = null;
@ -223,14 +223,14 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
case 1: case 1:
UserAccount newUser = new UserAccount(newCredentials.GetUserName(), UserAccount newUser = new UserAccount(newCredentials.GetUserName(),
newCredentials.GetPassword(), newCredentials.GetEmail(), newCredentials.GetPassword(), newCredentials.GetEmail(),
newCredentials.GetRole(), DateTime.UtcNow); newCredentials.GetRole(), DateTime.UtcNow);
accountService.CreateUserRecord(newUser, dbSource); accountService.CreateUserRecord(newUser,user.username, dbSource);
break; break;
// Edit account // Edit account
case 2: case 2:
UserAccount newEditUser = new UserAccount(newCredentials.GetUserName(), /* UserAccount newEditUser = new UserAccount(newCredentials.GetUserName(),
newCredentials.GetPassword(), DateTime.UtcNow); newCredentials.GetPassword(), DateTime.UtcNow);
accountService.EditUserRecord(newEditUser, dbSource); accountService.EditUserRecord(newEditUser, dbSource);*/
break; break;
// Delete account // Delete account
case 3: case 3:
@ -262,72 +262,9 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
} }
} }
string dbAction = user.NewUserName; string dbAction = user.username;
return dbAction; 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;
}
} }
} }

View File

@ -20,6 +20,11 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
string? userPassword = Console.ReadLine(); string? userPassword = Console.ReadLine();
return userPassword; return userPassword;
} }
/*public string ConfirmPassword()
{
Console.WriteLine();
string confirmPassword = newUser.NewPassword;
}*/
public string GetEmail() public string GetEmail()
{ {
Console.WriteLine("Please enter an email:"); Console.WriteLine("Please enter an email:");
@ -36,40 +41,35 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
// Admin Credentials // Admin Credentials
private string _userName; private string _userName;
private string _password; 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) public UserAccount(string un, string pwd, DateTime TimeStamp)
{ {
_userName = un; _userName = un;
_password = pwd; _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) public UserAccount(string newUN, string newPWD, string Email, string role, DateTime newTime)
{ {
_newUserName = newUN; _userName = newUN;
_newPassword = newPWD; _password = newPWD;
_newRole = role; _Role = role;
_newEmail = Email; _Email = Email;
_newTime = newTime; _Time = newTime;
} }
public UserAccount() public UserAccount()
{ {
_newRole = "regular"; _Role = "regular";
_newTime= DateTime.Now; _Time= DateTime.Now;
} }
public string NewUserName { get { return _newUserName; } }
public string NewPassword { get { return _newPassword; } } public string username { get { return _userName; } }
public string NewEmail { get { return _newEmail; } } public string password { get { return _password; } }
public string NewRole { get { return _newRole; } } public string email { get { return _Email; } }
public DateTime NewTime { get { return _newTime; } } public string role { get { return _Role; } }
public DateTime Time { get { return _Time; } }
} }
} }