Skip to content

Commit

Permalink
Merge pull request #4 from marcus-talbot42/login
Browse files Browse the repository at this point in the history
Login
  • Loading branch information
marcus-talbot42 authored Apr 17, 2024
2 parents 5ff3c7e + 4372581 commit 2188aae
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 59 deletions.
2 changes: 2 additions & 0 deletions ProjectB.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=19fd1edb_002D1417_002D4038_002Da919_002D0c34f0f5114d/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="TestAdditionCalculator" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;TestAncestor&gt;
&lt;TestId&gt;MSTest::30DFCAE0-5221-440C-8C75-963D08834F19::net7.0::ProjectBTest.UnitTest1&lt;/TestId&gt;
&lt;TestId&gt;MSTest::30DFCAE0-5221-440C-8C75-963D08834F19::net7.0::ProjectBTest.ui.MainMenuTest&lt;/TestId&gt;
&lt;TestId&gt;MSTest::30DFCAE0-5221-440C-8C75-963D08834F19::net8.0::ProjectBTest.UnitTest1&lt;/TestId&gt;
&lt;TestId&gt;MSTest::30DFCAE0-5221-440C-8C75-963D08834F19::net8.0::ProjectBTest.IO.JsonFileReaderTest.ShouldJsonToFileWhenPassedAListOfUsers&lt;/TestId&gt;
&lt;TestId&gt;MSTest::30DFCAE0-5221-440C-8C75-963D08834F19::net8.0::ProjectBTest.IO.JsonFileReaderTest&lt;/TestId&gt;
Expand Down
2 changes: 1 addition & 1 deletion ProjectB/Models/IEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ProjectB.Models;
/// </summary>
///
/// <typeparam name="TId">The type of the ID of the entity.</typeparam>
public interface IEntity<out TId> where TId : class
public interface IEntity<out TId>
{
/// <summary>
/// Returns the ID of the object it is called on. Mainly used to determine whether an ID is already taken, resulting
Expand Down
Empty file added ProjectB/Program.cs
Empty file.
92 changes: 92 additions & 0 deletions ProjectB/Resources/Translations.cs
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);
}
}
31 changes: 31 additions & 0 deletions ProjectB/Services/GuestService.cs
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();
}
}
1 change: 0 additions & 1 deletion ProjectB/Services/IService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace ProjectB.Services;

public interface IService<TEntity, TId>
where TEntity : IEntity<TId>
where TId : class
{

void Create(TEntity entity);
Expand Down
52 changes: 0 additions & 52 deletions ProjectB/Services/RondleidingService.cs

This file was deleted.

1 change: 0 additions & 1 deletion ProjectB/Services/UserService.cs
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;
Expand Down
46 changes: 46 additions & 0 deletions ProjectB/login/EmployeeLoginStrategy.cs
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;
}
}
19 changes: 19 additions & 0 deletions ProjectB/login/GuestLoginStrategy.cs
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);
}
}
6 changes: 6 additions & 0 deletions ProjectB/login/ILoginStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ProjectB.login;

public interface ILoginStrategy
{
Session Handle();
}
13 changes: 13 additions & 0 deletions ProjectB/login/Session.cs
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;
}
}
8 changes: 8 additions & 0 deletions ProjectB/login/UserRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ProjectB.login;

public enum UserRole
{
GUEST,
GUIDE,
DEPARTMENT_HEAD
}
7 changes: 7 additions & 0 deletions ProjectB/settings/Lanuage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ProjectB.settings;

public enum Language
{
NL,
EN
}
9 changes: 9 additions & 0 deletions ProjectB/settings/Settings.cs
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;
}
33 changes: 33 additions & 0 deletions ProjectB/ui/MainMenu.cs
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;
}
}

}
5 changes: 1 addition & 4 deletions ProjectBTest/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ namespace ProjectBTest;
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestAdditionCalculator()
{
}

}
Loading

0 comments on commit 2188aae

Please sign in to comment.