diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index 65c6564..b6ac8e3 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -1,16 +1,16 @@ -// See https://aka.ms/new-console-template for more information - +// See https://aka.ms/new-console-template for more information + using ConsoleApp; using ConsoleApp.Menu; using DataPersistence; -using Model; +using Model; using System.Linq; using System.Text; - -Console.WriteLine("Hello, World!\n\n"); - - -// TESTS: + +Console.WriteLine("Hello, World!\n\n"); + + +// TESTS: DataManager dataMgr = new DataManager(new Stubs()); //DataManager dataMgr = new DataManager(new DataContractXML(xmlFolderPath: "../../../../DataPersistence/data")); //DataManager dataMgr = new DataManager(new DataContractJSON()); @@ -22,14 +22,23 @@ dataMgr.Serializer = new DataContractJSON(); // /!\ here is an absolute path I put for testing purpose. It will only work on my computer so don't forget to change it whene you test. //dataMgr.Export(rc[2], "C:\\Users\\alex6\\Downloads\\recipe2.json"); //dataMgr.Import("C:\\Users\\alex6\\Downloads\\recipe2.json"); - + +Stub stub = new Stub(); +PasswordManager passwordManager = new PasswordManager(); RecipeCollection rc = new RecipeCollection("All recipes", dataMgr.Data[nameof(Recipe)].Cast().ToArray()); dataMgr.Save(); - + MenuManager menuMgr = new MenuManager(dataMgr); - + menuMgr.Loop(); + +foreach (RecipeCollection r in recipeCollections) + Console.WriteLine(r); + +List users = stub.ConstrucList(); +foreach (User u in users) + Console.WriteLine(u); -// press any key to quit -//Console.ReadKey(); +bool isPassCorrect = stub.VerifPass(); +Console.WriteLine(isPassCorrect); diff --git a/MCTG/ConsoleApp/Stub.cs b/MCTG/ConsoleApp/Stub.cs new file mode 100644 index 0000000..7bbf872 --- /dev/null +++ b/MCTG/ConsoleApp/Stub.cs @@ -0,0 +1,79 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp +{ + + internal struct Stub + { + private IPasswordManager passwordManager = new PasswordManager(); + + public List LoadRecipes() + { + List stub = new List(); + stub.AddRange(new[] + { + new Recipe(), + new Recipe("Cookies"), + new Recipe("Cookies", 23), + new Recipe("Cookies", null), + new Recipe("", null), + new Recipe("", 24), + new Recipe("Cookies", 24, + new PreparationStep(1)), + new Recipe("Cookies", 26, + new PreparationStep(1), + new PreparationStep(2, "Faire cuire.")) + }); + return stub; + } + + public List LoadRecipeCollection() + { + List stub = new List(); + stub.AddRange(new[] + { + new RecipeCollection("All", LoadRecipes().ToArray()), + new RecipeCollection("Starters", LoadRecipes().FindAll(x => x.Id.Equals(23)).ToArray()), + new RecipeCollection("Dishies", LoadRecipes().FindAll(x => x.Id.Equals(24)).ToArray()), + new RecipeCollection("Desserts", LoadRecipes().FindAll(x => x.Id.Equals(26)).ToArray()), + }); + return stub; + } + + public List ConstrucList() + { + List Users = new List(); + + User Roger = new User("Roger", "Rabbit", "carotte@mail.fr",passwordManager.HashPassword("password")); + User Dylan = new User("d", "r", "dr@mail.fr", passwordManager.HashPassword("dede")); + User Val = new User("V", "entin", "Valentin@mail.fr", passwordManager.HashPassword("valentin")); + + Users.Add(Roger); + Users.Add(Dylan); + Users.Add(Val); + return Users; + } + + public bool VerifPass() + { + User John = new User("John", "Doe", "JD@gmail.com", passwordManager.HashPassword("GIJD")); + string entryPass = "GIJD"; + + User Val = new User("V", "entin", "Valentin@mail.fr", passwordManager.HashPassword("valentin")); + Val.Password = passwordManager.HashPassword("jeChange"); + + bool isPasswordCorrect = passwordManager.VerifyPassword(John.Password, entryPass); + + return isPasswordCorrect; + } + public Stub() + { + + } + } +} diff --git a/MCTG/Model/Ingredient/Ingredient.cs b/MCTG/Model/Ingredient/Ingredient.cs new file mode 100644 index 0000000..a30d0d0 --- /dev/null +++ b/MCTG/Model/Ingredient/Ingredient.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model.Ingredient +{ + internal class Ingredient + { + } +} diff --git a/MCTG/Model/User/IPasswordManager.cs b/MCTG/Model/User/IPasswordManager.cs index 12f0e0a..a87d960 100644 --- a/MCTG/Model/User/IPasswordManager.cs +++ b/MCTG/Model/User/IPasswordManager.cs @@ -8,9 +8,8 @@ namespace Model { public interface IPasswordManager { - public void changePassword(User user, string newPassword); - public string HashPassword(User user); - public bool VerifyPassword(string hashedPassword); + public int HashPassword(string password); + public bool VerifyPassword(int hashedPassword,string password); } } diff --git a/MCTG/Model/User/PasswordManager.cs b/MCTG/Model/User/PasswordManager.cs index 59bc784..d762e42 100644 --- a/MCTG/Model/User/PasswordManager.cs +++ b/MCTG/Model/User/PasswordManager.cs @@ -8,19 +8,20 @@ namespace Model { public class PasswordManager : IPasswordManager { - public void changePassword(User user, string newPassword) - { - throw new NotImplementedException(); - } - public string HashPassword(User user) + public int HashPassword(string password) { - throw new NotImplementedException(); + int hashedPassword = password.GetHashCode(); + return hashedPassword; } - public bool VerifyPassword(string hashedPassword) + public bool VerifyPassword(int hashedPassword, string passwordEntered ) { - throw new NotImplementedException(); + int passwordEnteredHashed = passwordEntered.GetHashCode(); + if ( passwordEnteredHashed == hashedPassword) + return true; + else return false; + } } } diff --git a/MCTG/Model/User/User.cs b/MCTG/Model/User/User.cs index cbec8c4..6f930e4 100644 --- a/MCTG/Model/User/User.cs +++ b/MCTG/Model/User/User.cs @@ -5,6 +5,7 @@ using System.Collections.ObjectModel; using System.Threading.Tasks; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; +using System.Text; namespace Model { @@ -20,8 +21,7 @@ namespace Model private string surname=""; private string mail = ""; private string picture = ""; - private string password = ""; - //private string defaultUserSavePath = ""; + private int password ; private List priorities; #endregion @@ -79,16 +79,14 @@ namespace Model } } - /// - /// Property to initiate password, change it, and - /// - public string Password + public int Password { - get { return password; } - - set { password = value; } + get => password; + set => password = value; + } - + + /// /// For now, we define the ProfilPict as a string which is "PhotoParDefaut" /// when the value is null. @@ -111,19 +109,20 @@ namespace Model set=> priorities = value; } - public override bool Equals(object? obj) + public override bool Equals(object? other) { - if (obj == null) return false; - if (obj == this) return true; - return Equals(obj); - } - public bool Equals(User? other) + if (other == null) return false; + if (other == this) return true; + return Equals(other); + } + + public bool Equals(User? other) { - if (other == null ) return false; + if (other == null) return false; return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); } - + #endregion @@ -135,11 +134,12 @@ namespace Model /// The name of the user /// The surname of the user /// The user needs an email to login. - public User(string name, string surname, string mail) + public User(string name, string surname, string mail, int password) { Name = name; Surname = surname; Mail = mail; + Password = password; priorities = new List { Priority.Gourmet, Priority.Economic, diff --git a/MCTG/Tests/Model_UnitTests/Model_UnitTests - Backup.csproj b/MCTG/Tests/Model_UnitTests/Model_UnitTests - Backup.csproj new file mode 100644 index 0000000..cbc7829 --- /dev/null +++ b/MCTG/Tests/Model_UnitTests/Model_UnitTests - Backup.csproj @@ -0,0 +1,31 @@ +<<<<<<< HEAD + +======= + + +>>>>>>> feature/18-model-user + + net7.0 + enable + enable + false + true + Debug;Release;CI + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + \ No newline at end of file diff --git a/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj b/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj index 2a658d9..ce77636 100644 --- a/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj +++ b/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj @@ -1,4 +1,4 @@ - + net7.0 enable diff --git a/MCTG/Tests/Model_UnitTests/test_unit_user.cs b/MCTG/Tests/Model_UnitTests/test_unit_user.cs index 1756e20..5df6579 100644 --- a/MCTG/Tests/Model_UnitTests/test_unit_user.cs +++ b/MCTG/Tests/Model_UnitTests/test_unit_user.cs @@ -12,8 +12,13 @@ namespace Model_UnitTests [Fact] public void TestConstructUser() { - User? user = new User("Bob","Dylan", "bd@gmail.com"); - Assert.NotNull(user); + PasswordManager passwordManager = new PasswordManager(); + User user = new User("Bob", "Dylan", "bd@gmail.com", passwordManager.HashPassword("bobby")); + Assert.Equal("Bob", user.Name); + Assert.Equal("Dylan", user.Surname); + Assert.Equal("bd@gmail.com", user.Mail); + Assert.Equal(passwordManager.HashPassword("bobby"), user.Password); + Assert.NotNull(user.Priorities); } } }