diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index 6ed8651..f53be3e 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -1,42 +1,46 @@ -// 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: -DataManager dataMgr = new DataManager(new Stubs()); -//DataManager dataMgr = new DataManager(new DataContractXML(xmlFolderPath: "../../../../DataPersistence/data")); + +Console.WriteLine("Hello, World!\n\n"); + + +// TESTS: +//DataManager dataMgr = new DataManager(new Stubs()); +DataManager dataMgr = new DataManager(new DataContractXML()); //DataManager dataMgr = new DataManager(new DataContractJSON()); -//dataMgr.Serializer = new DataContractXML(xmlFolderPath: "../../../../DataPersistence/data"); -dataMgr.Serializer = new DataContractJSON(); +//dataMgr.Serializer = new DataContractXML(); +//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"); +PasswordManager passwordManager = new PasswordManager(); RecipeCollection rc = new RecipeCollection("All recipes", dataMgr.Data[nameof(Recipe)].Cast().ToArray()); -User user = new User("Pedros", "Amigos", "pedrosamigos@hotmail.com"); -rc[0].AddReview(new Review(user, 1, "bonne recette !1")); -rc[0].AddReview(new Review(user, 1, "bonne recette !2")); -rc[0].AddReview(new Review(user, 4, "bonne recette !3")); -rc[0].AddReview(new Review(user, 5, "bonne recette !4")); -rc[0].AddReview(new Review(user, 3, "bonne recette !5")); -rc[0].AddReview(new Review(user, 2, "bonne recette !6")); +User user = dataMgr.Data[nameof(User)].Cast().Last(); -dataMgr.Save(); +//rc[0].AddReview(new Review(user, 1, "bonne recette !1")); +//rc[0].AddReview(new Review(user, 1, "bonne recette !2")); +//rc[0].AddReview(new Review(user, 4, "bonne recette !3")); +//rc[0].AddReview(new Review(user, 5, "bonne recette !4")); +//rc[0].AddReview(new Review(user, 3, "bonne recette !5")); +//rc[0].AddReview(new Review(user, 2, "bonne recette !6")); +//rc[0].AddReview(new Review(user, 2, "peut etre pas ducoup !")); +//rc[1].AddReview(new Review(user, 2, "Mais celle-ci oui !")); +dataMgr.Save(); + MenuManager menuMgr = new MenuManager(dataMgr); - + menuMgr.Loop(); -// press any key to quit -//Console.ReadKey(); +Console.WriteLine(passwordManager.VerifyPassword(user.Password, "pamigos")); +Console.ReadKey(); diff --git a/MCTG/DataPersistence/DataPersistence.csproj b/MCTG/DataPersistence/DataPersistence.csproj index d5050a6..4b28c7b 100644 --- a/MCTG/DataPersistence/DataPersistence.csproj +++ b/MCTG/DataPersistence/DataPersistence.csproj @@ -10,8 +10,4 @@ - - - - diff --git a/MCTG/DataPersistence/Stubs.cs b/MCTG/DataPersistence/Stubs.cs index cc09f39..1539bc5 100644 --- a/MCTG/DataPersistence/Stubs.cs +++ b/MCTG/DataPersistence/Stubs.cs @@ -14,6 +14,8 @@ namespace DataPersistence { public Dictionary> Load() { + PasswordManager passwordManager = new PasswordManager(); + Dictionary> data = new Dictionary> { { @@ -86,6 +88,24 @@ namespace DataPersistence }) }) #endregion + }, + { + #region Data: User + nameof(User), + new List(new[] + { + new User( + name: "Admin", + surname: "Admin", + mail: "admin@mctg.fr", + password: passwordManager.HashPassword("admin")), + new User( + name: "Pedros", + surname: "Amigos", + mail: "pedrosamigos@hotmail.com", + password: passwordManager.HashPassword("pamigos")) + }) + #endregion } }; diff --git a/MCTG/DataPersistence/data/data.json b/MCTG/DataPersistence/data/data.json deleted file mode 100644 index 8d25dfd..0000000 --- a/MCTG/DataPersistence/data/data.json +++ /dev/null @@ -1,168 +0,0 @@ -[ - { - "Key": "Recipe", - "Value": [ - { - "__type": "recipe:#Model", - "id": 26700, - "preparation-steps": [ - { - "description": "Faire cuire.", - "order": 1 - }, - { - "description": "Manger.", - "order": 2 - } - ], - "title": "Cookies classiques" - }, - { - "__type": "recipe:#Model", - "id": 16433, - "preparation-steps": [ - { - "description": "Moulinez la pâte.", - "order": 1 - }, - { - "description": "Faire cuire pendant une bonne heure.", - "order": 2 - }, - { - "description": "Sortir du four et mettre dans un plat.", - "order": 3 - } - ], - "title": "Cookies au chocolat" - }, - { - "__type": "recipe:#Model", - "id": 26093, - "preparation-steps": [ - { - "description": "Achetez les ingrédients.", - "order": 1 - }, - { - "description": "Préparez le matériel. Ustensiles et tout.", - "order": 2 - }, - { - "description": "Pleurez.", - "order": 3 - } - ], - "title": "Gateau nature" - }, - { - "__type": "recipe:#Model", - "id": 21481, - "preparation-steps": [ - { - "description": "Achetez les légumes.", - "order": 1 - }, - { - "description": "Préparez le plat. Ustensiles et préchauffez le four.", - "order": 2 - }, - { - "description": "Coupez les pommes en morceaux et disposez-les sur le plat.", - "order": 3 - }, - { - "description": "Mettez enfin le plat au four, puis une fois cuit, dégustez !", - "order": 4 - } - ], - "title": "Gateau au pommes" - }, - { - "__type": "recipe:#Model", - "id": 15049, - "preparation-steps": [ - { - "description": "Ajouter les oeufs.", - "order": 1 - }, - { - "description": "Ajouter la farine.", - "order": 2 - }, - { - "description": "Ajouter 100g de chocolat fondu.", - "order": 3 - }, - { - "description": "Mélanger le tout.", - "order": 4 - }, - { - "description": "Faire cuire 45h au four traditionnel.", - "order": 5 - } - ], - "title": "Gateau au chocolat" - }, - { - "__type": "recipe:#Model", - "id": 28153, - "preparation-steps": [ - { - "description": "Faire une cuisson bien sec de la dinde à la poêle", - "order": 1 - }, - { - "description": "Mettre la dinde au frigo.", - "order": 2 - }, - { - "description": "Mettre le jambon dans le micro-onde.", - "order": 3 - }, - { - "description": "Faire chauffer 3min.", - "order": 4 - }, - { - "description": "Présentez sur un plat la dinde et le jambon : Miam !", - "order": 5 - } - ], - "title": "Dinde au jambon" - }, - { - "__type": "recipe:#Model", - "id": 8053, - "preparation-steps": [ - { - "description": "Trouvez des épices de curry.", - "order": 1 - }, - { - "description": "Trouvez maintenant du poulet.", - "order": 2 - }, - { - "description": "Coupez la tête du poulet et posez-la dans un plat.", - "order": 3 - }, - { - "description": "Parsemez d'épices curry la tête de la poule.", - "order": 4 - }, - { - "description": "Mettre le tout au four traditionnel 30min.", - "order": 5 - }, - { - "description": "Dégustez en famille !", - "order": 6 - } - ], - "title": "Poulet au curry" - } - ] - } -] \ No newline at end of file diff --git a/MCTG/DataPersistence/data/data.xml b/MCTG/DataPersistence/data/data.xml deleted file mode 100644 index bc21b40..0000000 --- a/MCTG/DataPersistence/data/data.xml +++ /dev/null @@ -1,184 +0,0 @@ - - - - Recipe - - - 9062 - - - Faire cuire. - 1 - - - Manger. - 2 - - - Cookies classiques - - - 27627 - - - Moulinez la pâte. - 1 - - - Faire cuire pendant une bonne heure. - 2 - - - Sortir du four et mettre dans un plat. - 3 - - - Cookies au chocolat - - - 8517 - - - Achetez les ingrédients. - 1 - - - Préparez le matériel. Ustensiles et tout. - 2 - - - Pleurez. - 3 - - - Gateau nature - - - 6161 - - - Achetez les légumes. - 1 - - - Préparez le plat. Ustensiles et préchauffez le four. - 2 - - - Coupez les pommes en morceaux et disposez-les sur le plat. - 3 - - - Mettez enfin le plat au four, puis une fois cuit, dégustez ! - 4 - - - Gateau au pommes - - - 17869 - - - Ajouter les oeufs. - 1 - - - Ajouter la farine. - 2 - - - Ajouter 100g de chocolat fondu. - 3 - - - Mélanger le tout. - 4 - - - Faire cuire 45h au four traditionnel. - 5 - - - Gateau au chocolat - - - 4810 - - - Faire une cuisson bien sec de la dinde à la poêle - 1 - - - Mettre la dinde au frigo. - 2 - - - Mettre le jambon dans le micro-onde. - 3 - - - Faire chauffer 3min. - 4 - - - Présentez sur un plat la dinde et le jambon : Miam ! - 5 - - - Dinde au jambon - - - 13570 - - - Trouvez des épices de curry. - 1 - - - Trouvez maintenant du poulet. - 2 - - - Coupez la tête du poulet et posez-la dans un plat. - 3 - - - Parsemez d'épices curry la tête de la poule. - 4 - - - Mettre le tout au four traditionnel 30min. - 5 - - - Dégustez en famille ! - 6 - - - Poulet au curry - - - 26918 - - - Achetez les ingrédients. - 1 - - - Préparez le matériel. Ustensiles et tout. - 2 - - - Pleurez. - 3 - - - Aprenez de vos echecs. - 4 - - - Gateau nature v2 - - - - \ No newline at end of file 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/Recipes/Recipe.cs b/MCTG/Model/Recipes/Recipe.cs index b7ced0d..fe81d0a 100644 --- a/MCTG/Model/Recipes/Recipe.cs +++ b/MCTG/Model/Recipes/Recipe.cs @@ -158,6 +158,11 @@ namespace Model { sb.AppendFormat("\t* {0}\n", ps.ToString()); } + sb.AppendLine(); + foreach (Review review in Reviews) + { + sb.AppendLine(review.ToString()); + } return sb.ToString(); } #endregion diff --git a/MCTG/Model/Recipes/Review.cs b/MCTG/Model/Recipes/Review.cs index 198c1b3..b98d498 100644 --- a/MCTG/Model/Recipes/Review.cs +++ b/MCTG/Model/Recipes/Review.cs @@ -66,7 +66,8 @@ namespace Model } public Review(int stars, string content) - : this(new User("...", "...", "...@..."), null, stars, content) + : this(new User("admin", "admin", "admin@mctg.fr", new PasswordManager().HashPassword("admin")), + null, stars, content) { } 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 97bd95e..9b9503e 100644 --- a/MCTG/Model/User/User.cs +++ b/MCTG/Model/User/User.cs @@ -5,24 +5,26 @@ using System.Collections.ObjectModel; using System.Threading.Tasks; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; +using System.Text; +using System.Runtime.Serialization; namespace Model { /// /// A user is an entity with a name, a surname, mail, profilePict and a list of priority. - /// This user can login with a Id and password + /// This user can login with an Id and a password /// + [DataContract(Name = "user")] public class User : IEquatable { #region Private Attributes - private string name=""; - private string surname=""; - private string mail = ""; - private string picture = ""; - private string password = ""; - //private string defaultUserSavePath = ""; - private List priorities; + [DataMember] private string name=""; + [DataMember] private string surname=""; + [DataMember] private string mail = ""; + [DataMember] private string picture = ""; + [DataMember] private int password ; + [DataMember] private List priorities; #endregion #region Properties @@ -79,16 +81,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,18 +111,23 @@ 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); + 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); } + public override int GetHashCode() + { + throw new NotImplementedException(); + } #endregion @@ -135,11 +140,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, @@ -150,6 +156,8 @@ namespace Model } + + #endregion 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); } } }