diff --git a/notus/Biblioteque_de_Class/HashCodeModel.cs b/notus/Biblioteque_de_Class/HashCodeModel.cs index 729d14f..7bfbaeb 100644 --- a/notus/Biblioteque_de_Class/HashCodeModel.cs +++ b/notus/Biblioteque_de_Class/HashCodeModel.cs @@ -11,16 +11,18 @@ namespace Biblioteque_de_Class { public static string GetSHA256Hash(string input) { - using SHA256 sha256Hash = SHA256.Create(); - byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); - - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < bytes.Length; i++) + using (SHA256 sha256Hash = SHA256.Create()) { - builder.Append(bytes[i].ToString("x2")); - } + byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); + + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < bytes.Length; i++) + { + builder.Append(bytes[i].ToString("x2")); + } - return builder.ToString(); + return builder.ToString(); + } } } } diff --git a/notus/Biblioteque_de_Class/User.cs b/notus/Biblioteque_de_Class/User.cs index 0e180a9..c2cc5d5 100644 --- a/notus/Biblioteque_de_Class/User.cs +++ b/notus/Biblioteque_de_Class/User.cs @@ -192,13 +192,8 @@ namespace Biblioteque_de_Class } } Note note; - if (NoteList == null) { note = new Note(0, name, imagePath, this); } - else - { - Note? tocheckid = NoteList.LastOrDefault(); - if (tocheckid==null) - note = new Note(tocheckid.id + 1, name, imagePath, this); - } + if (NoteList.Count == 0) { note = new Note(0, name, imagePath, this); } + else { note = new Note(NoteList[NoteList.Count - 1].id + 1, name, imagePath, this); } NoteList.Add(note); NoteTagged.Add(note, new List()); return note; @@ -355,7 +350,6 @@ namespace Biblioteque_de_Class public void ChangePassword(string newPassword) { if (newPassword == null) { return; } - if ( Password == newPassword) { throw new AlreadyExistException("this username is the same."); } if (newPassword.Length < 8) { throw new NotAllowedException("this password is too short."); } Password = HashCodeModel.GetSHA256Hash(newPassword).ToString(); } diff --git a/notus/Notus_Console/Program.cs b/notus/Notus_Console/Program.cs index cac33da..d6a7874 100644 --- a/notus/Notus_Console/Program.cs +++ b/notus/Notus_Console/Program.cs @@ -10,7 +10,6 @@ using System.Text; PersistenceManager manager = new(new Stub()); Database db = manager.LoadDatabaseData(); - // initialization zone============================================================================== bool arreter = true; @@ -71,6 +70,10 @@ bool Choix_DefaultNon() // pour selectionner une note dans le menu note bool Choix_Note() { + foreach (Note notetodisplay in u.NoteList) + { + Console.WriteLine("- " + notetodisplay.Name); + } continuerboucle = true; while (continuerboucle) { @@ -187,11 +190,13 @@ while (arreter) } if (!connection) { - if (Database.ComparePassword(u, HashCodeModel.GetSHA256Hash(u.Password).ToString())) + + if (Database.ComparePassword(u, HashCodeModel.GetSHA256Hash(password).ToString())) { u.IsConnected = true; Console.WriteLine("\nConnection réussie !\n"); menu = false; + break; } else { @@ -206,6 +211,8 @@ while (arreter) connection = Choix_DefaultNon(); } + + //inscription while (inscription) { @@ -258,6 +265,10 @@ while (arreter) { case "1": note = true; + foreach (Note notetodisplay in u.NoteList) + { + Console.WriteLine("- " + notetodisplay.Name); + } break; case "2": tags = true; @@ -266,6 +277,7 @@ while (arreter) para = true; break; case "4": + menu = true; Console.WriteLine("\ndéconnecté! \n"); u.IsConnected = false; u = uvide; @@ -277,10 +289,6 @@ while (arreter) while (note) { - foreach (Note notetodisplay in u.NoteList) - { - Console.WriteLine( "- " + notetodisplay.Name); - } Console.WriteLine("\n|--------------------------------------|"); Console.WriteLine("| |"); Console.WriteLine("| menu - note |"); @@ -566,13 +574,6 @@ while (arreter) } break; case "13": - /* - * ajouter une date ou une fourchette de date? - * ajouter des tags - * écrire le nom de la note? - * dans cette ordre on peut de façon plus simple - */ - //----------------------------------------------------------------------------aaaaaaaaaaaaaaaaaaaaaaa List wantedNotes = new List(); Console.WriteLine("\nEntrez le nom de la note à rechercher :"); @@ -656,6 +657,7 @@ while (arreter) Console.WriteLine("choisissez le tags à rechercher"); string? tagstoresearch = Console.ReadLine(); if (tagstoresearch == null) { continue; } + if (wantedNotes == null) { Console.WriteLine("Aucun resultat !"); break; } wantedNotes = u.SearchNoteByTag(wantedNotes, tagstoresearch); } if (wantedNotes == null) { Console.WriteLine("Aucun resultat !"); break; } @@ -886,11 +888,6 @@ while (arreter) { u.ChangePassword(wantedNewPassword); } - catch(AlreadyExistException ex) - { - Console.WriteLine(ex.Message); - break; - } catch(NotAllowedException ex) { Console.WriteLine(ex.Message); @@ -1132,4 +1129,4 @@ while (arreter) } } } -manager.SaveDatabaseData(db); +//manager.SaveDatabaseData(db); diff --git a/notus/Notus_Persistence/Stub.cs b/notus/Notus_Persistence/Stub.cs index cec6616..ddd2b77 100644 --- a/notus/Notus_Persistence/Stub.cs +++ b/notus/Notus_Persistence/Stub.cs @@ -25,45 +25,32 @@ namespace Notus_Persistance User uselect; // add some users - database.AddUser(new User("Nicolas", "leHeros@gmail.com", "Feur")); + database.AddUser(new User("Nicolas", "leHeros@gmail.com", "FeurFeur")); database.AddUser(new User("Benjamin", "labsent@gmail.com", "Moto2005")); database.AddUser(new User("Liam", "liammonchanin@gmail.com", "Baguette")); - database.AddUser(new User("Brigitte", "Macroutte@gmail.com", "49Trois")); + database.AddUser(new User("Brigitte", "Macroutte@gmail.com", "4949Trois")); // add some notes and tags to go faster - foreach(User user in database.UserList.Where(x => x.Username.Contains("m"))) + + for (int i = 0; i < database.UserList.Count; i++) { - user.CreateNote("Note 1", ""); - user.CreateNote("Note 2", ""); - user.CreateNote("Note 3", ""); - user.CreateTag("Tag 1","#FA0034"); - user.CreateTag("Tag 2", "#2500A4"); + database.UserList[i].CreateNote($"Note {i}", "DefaultLogo.png"); + database.UserList[i].CreateTag($"Tag {i}", "#5555FF"); } // add note to user for sharing note test mixed with tag - uselect = (User)database.UserList.Where(x => x.Username == "Nicolas"); - uselect.CreateNote("Note 4", "Logo_1"); - uselect.CreateTag("Tag 3", "#00FF00"); - nselect = (Note)uselect.NoteList.Where(x => x.Name == "Note 4"); - uselect.AddTagFromNoteList(nselect, (Tags)uselect.TagList.Where(x => x.Name == "Tag 3")); - nselect.AddCollaborator(uselect,(User)database.UserList.Where(x => x.Username == "Benjamin")); - uselect = (User)database.UserList.Where(x => x.Username == "Benjamin"); - uselect.CreateTag("Tag 4", "#FF0000"); - // add some default logos and themes - database.DefaultLogoList.Add(new Logo("Logo_1", "logo")); - database.DefaultLogoList.Add(new Logo("Logo_2", "logo")); - database.DefaultLogoList.Add(new Logo("Logo_3", "logo")); - List colorListHexaCode = new("FF0000,00FF00,0000FF".Split(',')); - database.AddTheme(new Theme("Theme_1", colorListHexaCode)); - colorListHexaCode = new("FF00FF,00FFFF,FFFF00".Split(',')); - database.AddTheme(new Theme("Theme_2", colorListHexaCode)); - colorListHexaCode = new("000000,FFFFFF,000000".Split(',')); - database.AddTheme(new Theme("Theme_3", colorListHexaCode)); + uselect = database.UserList[0]; + nselect = uselect.NoteList[0]; + nselect.AddCollaborator(uselect, database.UserList[1]); + nselect.AddCollaborator(uselect, database.UserList[2]); + uselect.AddTagFromNoteList(nselect, uselect.TagList[0]); + nselect.AddEditor(uselect, database.UserList[2]); + // add some default logos and themes foreach (User user in database.UserList) { - user.ChangePassword(HashCodeModel.GetSHA256Hash(user.Password).ToString()); + user.ChangePassword(user.Password); } return database; @@ -71,11 +58,18 @@ namespace Notus_Persistance public List LoadDefaultTheme() { - throw new NotImplementedException(); + List DefaultThemeList = new List(); + DefaultThemeList.Add(new("blacktheme", "#000000,#FF00FF,#OOFFOO".Split().ToList())); + DefaultThemeList.Add(new("whitetheme", "#FFFFFF,#FF00FF,#OOFFOO".Split().ToList())); + return DefaultThemeList; } public List LoadDefaultLogo() { - throw new NotImplementedException(); + List DefaultLogoList = new List(); + DefaultLogoList.Add(new("default","DefaultLogo.png")); + DefaultLogoList.Add(new("1", "Logo1.png")); + DefaultLogoList.Add(new("2", "Logo2.png")); + return DefaultLogoList; } }