-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from marcus-talbot42/login
Login
- Loading branch information
Showing
19 changed files
with
329 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using ProjectB.settings; | ||
|
||
namespace ProjectB.Resources; | ||
|
||
public class Translations | ||
{ | ||
private const string MAIN_MENU_NL = """ | ||
Welkom! | ||
Kies een van de onderstaande opties om door te gaan: | ||
1) Log in als gast | ||
2) Log in al medewerker | ||
3) Switch language to English | ||
"""; | ||
|
||
private const string MAIN_MENU_EN = """ | ||
Welcome! | ||
Choose one of the options below to continue: | ||
1) Login as a guest | ||
2) Login as an employee | ||
3) Verander de taal naar Nederlands | ||
"""; | ||
|
||
private const string NOT_IMPLEMENTED_NL = "Deze feature is nog niet geimplementeerd.\n"; | ||
|
||
private const string NOT_IMPLEMENTED_EN = "This feature has not been implemented yet.\n"; | ||
|
||
private const string LANGUAGE_CHANGED_NL = "Taal veranderd naar Nederlands.\n"; | ||
|
||
private const string LANGUAGE_CHANGED_EN = "Language changed to English.\n"; | ||
|
||
private const string LOGIN_PROMPT_GUEST_NL = "Geef uw ticket-nummer in:"; | ||
|
||
private const string LOGIN_PROMPT_GUEST_EN = "Please enter your ticket-number"; | ||
|
||
private const string LOGIN_PROMPT_EMPLOYEE_NL = "Geef uw gebruikersnaam in:"; | ||
|
||
private const string LOGIN_PROMPT_EMPLOYEE_EN = "Enter your username:"; | ||
|
||
private const string LOGIN_PROMPT_EMPLOYEE_PASSWORD_NL = "Geef uw wachtwoord in:"; | ||
|
||
private const string LOGIN_PROMPT_EMPLOYEE_PASSWORD_EN = "Enter your password:"; | ||
|
||
public static string translation(string name) | ||
{ | ||
if (Settings.Language == Language.NL) | ||
{ | ||
switch(name) | ||
{ | ||
case "MAIN_MENU": | ||
return MAIN_MENU_NL; | ||
case "NOT_IMPLEMENTED": | ||
return NOT_IMPLEMENTED_NL; | ||
case "LANGUAGE_CHANGED": | ||
return LANGUAGE_CHANGED_NL; | ||
case "LOGIN_PROMPT_GUEST": | ||
return LOGIN_PROMPT_GUEST_NL; | ||
case "LOGIN_PROMPT_EMPLOYEE": | ||
return LOGIN_PROMPT_EMPLOYEE_NL; | ||
case "LOGIN_PROMPT_EMPLOYEE_PASSWORD": | ||
return LOGIN_PROMPT_EMPLOYEE_PASSWORD_NL; | ||
default: | ||
return String.Format("Error: Translation not found for {0}", name); | ||
} | ||
} | ||
|
||
if (Settings.Language == Language.EN) | ||
{ | ||
switch (name) | ||
{ | ||
case "MAIN_MENU": | ||
return MAIN_MENU_EN; | ||
case "NOT_IMPLEMENTED": | ||
return NOT_IMPLEMENTED_EN; | ||
case "LANGUAGE_CHANGED": | ||
return LANGUAGE_CHANGED_EN; | ||
case "LOGIN_PROMPT_GUEST": | ||
return LOGIN_PROMPT_GUEST_EN; | ||
case "LOGIN_PROMPT_EMPLOYEE": | ||
return LOGIN_PROMPT_EMPLOYEE_EN; | ||
case "LOGIN_PROMPT_EMPLOYEE_PASSWORD": | ||
return LOGIN_PROMPT_EMPLOYEE_PASSWORD_EN; | ||
default: | ||
return String.Format("Error: Translation not found for {name}", name); | ||
} | ||
} | ||
return String.Format("Error: Translation not found for {name}", name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using ProjectB.Models; | ||
using ProjectB.Repositories; | ||
|
||
namespace ProjectB.Services; | ||
|
||
public class GuestService : IService<Guest, string> | ||
{ | ||
|
||
private static readonly Lazy<GuestService> Lazy = new(() => new GuestService()); | ||
public static GuestService Instance => Lazy.Value; | ||
|
||
private static readonly GuestRepository Repository = GuestRepository.Instance; | ||
|
||
public void Create(Guest entity) | ||
{ | ||
if (Repository.FindById(entity.GetId()) == null) | ||
{ | ||
Repository.Save(entity); | ||
} | ||
} | ||
|
||
public void Update(Guest entity, string id) | ||
{ | ||
Repository.Save(entity); | ||
} | ||
|
||
public void Delete(string id) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using ProjectB.Exceptions; | ||
using ProjectB.Models; | ||
using ProjectB.Repositories; | ||
|
||
namespace ProjectB.Services; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Security; | ||
using ProjectB.Resources; | ||
|
||
namespace ProjectB.login; | ||
|
||
public class EmployeeLoginStrategy: ILoginStrategy | ||
{ | ||
public Session Handle() | ||
{ | ||
Console.WriteLine(Translations.translation("LOGIN_PROMPT_EMPLOYEE")); | ||
string? username = Console.ReadLine(); | ||
Console.WriteLine(Translations.translation("LOGIN_PROMPT_EMPLOYEE_PASSWORD")); | ||
SecureString? password = GetPassword(); | ||
|
||
// TODO: Check password, and get UserRole from file. | ||
|
||
return new Session(username!, UserRole.GUIDE); // TODO: user proper UserRole. | ||
} | ||
|
||
private SecureString GetPassword() | ||
{ | ||
var pwd = new SecureString(); | ||
while (true) | ||
{ | ||
ConsoleKeyInfo i = Console.ReadKey(true); | ||
if (i.Key == ConsoleKey.Enter) | ||
{ | ||
break; | ||
} | ||
else if (i.Key == ConsoleKey.Backspace) | ||
{ | ||
if (pwd.Length > 0) | ||
{ | ||
pwd.RemoveAt(pwd.Length - 1); | ||
Console.Write("\b \b"); | ||
} | ||
} | ||
else if (i.KeyChar != '\u0000' ) // KeyChar == '\u0000' if the key pressed does not correspond to a printable character, e.g. F1, Pause-Break, etc | ||
{ | ||
pwd.AppendChar(i.KeyChar); | ||
Console.Write("*"); | ||
} | ||
} | ||
return pwd; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using ProjectB.Resources; | ||
|
||
namespace ProjectB.login; | ||
|
||
public class GuestLoginStrategy: ILoginStrategy | ||
{ | ||
|
||
|
||
|
||
public Session Handle() | ||
{ | ||
Console.WriteLine(Translations.translation("LOGIN_PROMPT_GUEST")); | ||
string? ticketNumber = Console.ReadLine(); | ||
|
||
// TODO: Check whether ticket is valid | ||
|
||
return new Session(ticketNumber!, UserRole.GUEST); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace ProjectB.login; | ||
|
||
public interface ILoginStrategy | ||
{ | ||
Session Handle(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace ProjectB.login; | ||
|
||
public class Session | ||
{ | ||
public string Username { get; private set; } | ||
public UserRole Role { get; private set; } | ||
|
||
public Session(string username, UserRole role) | ||
{ | ||
Username = username; | ||
Role = role; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace ProjectB.login; | ||
|
||
public enum UserRole | ||
{ | ||
GUEST, | ||
GUIDE, | ||
DEPARTMENT_HEAD | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace ProjectB.settings; | ||
|
||
public enum Language | ||
{ | ||
NL, | ||
EN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using ProjectB.login; | ||
|
||
namespace ProjectB.settings; | ||
|
||
public class Settings | ||
{ | ||
public static Language Language = Language.NL; | ||
public static Session? CurrentSession; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using ProjectB.login; | ||
using ProjectB.Resources; | ||
using ProjectB.settings; | ||
|
||
namespace ProjectB.ui; | ||
|
||
public class MainMenu | ||
{ | ||
|
||
public void ShowMenu() | ||
{ | ||
Console.WriteLine(Translations.translation("MAIN_MENU")); | ||
} | ||
|
||
public void HandleInput(char input) | ||
{ | ||
Console.WriteLine("\n"); | ||
switch (input) | ||
{ | ||
case '1': | ||
Settings.CurrentSession = new GuestLoginStrategy().Handle(); | ||
break; | ||
case '2': | ||
Settings.CurrentSession = new EmployeeLoginStrategy().Handle(); | ||
break; | ||
case '3': | ||
Settings.Language = Settings.Language == Language.NL ? Language.EN : Language.NL; | ||
Console.WriteLine(Translations.translation("LANGUAGE_CHANGED")); | ||
break; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.