reglage bug programs et finition

pull/15/head
Matheo THIERRY 2 years ago
parent 1b4352e22b
commit 9bbd0f3e4f

@ -11,16 +11,18 @@ namespace Biblioteque_de_Class
{ {
public static string GetSHA256Hash(string input) public static string GetSHA256Hash(string input)
{ {
using SHA256 sha256Hash = SHA256.Create(); 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++)
{ {
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();
}
} }
} }
} }

@ -192,13 +192,8 @@ namespace Biblioteque_de_Class
} }
} }
Note note; Note note;
if (NoteList == null) { note = new Note(0, name, imagePath, this); } if (NoteList.Count == 0) { note = new Note(0, name, imagePath, this); }
else else { note = new Note(NoteList[NoteList.Count - 1].id + 1, name, imagePath, this); }
{
Note? tocheckid = NoteList.LastOrDefault();
if (tocheckid==null)
note = new Note(tocheckid.id + 1, name, imagePath, this);
}
NoteList.Add(note); NoteList.Add(note);
NoteTagged.Add(note, new List<Tags>()); NoteTagged.Add(note, new List<Tags>());
return note; return note;
@ -355,7 +350,6 @@ namespace Biblioteque_de_Class
public void ChangePassword(string newPassword) public void ChangePassword(string newPassword)
{ {
if (newPassword == null) { return; } 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."); } if (newPassword.Length < 8) { throw new NotAllowedException("this password is too short."); }
Password = HashCodeModel.GetSHA256Hash(newPassword).ToString(); Password = HashCodeModel.GetSHA256Hash(newPassword).ToString();
} }

@ -10,7 +10,6 @@ using System.Text;
PersistenceManager manager = new(new Stub()); PersistenceManager manager = new(new Stub());
Database db = manager.LoadDatabaseData(); Database db = manager.LoadDatabaseData();
// initialization zone============================================================================== // initialization zone==============================================================================
bool arreter = true; bool arreter = true;
@ -71,6 +70,10 @@ bool Choix_DefaultNon()
// pour selectionner une note dans le menu note // pour selectionner une note dans le menu note
bool Choix_Note() bool Choix_Note()
{ {
foreach (Note notetodisplay in u.NoteList)
{
Console.WriteLine("- " + notetodisplay.Name);
}
continuerboucle = true; continuerboucle = true;
while (continuerboucle) while (continuerboucle)
{ {
@ -187,11 +190,13 @@ while (arreter)
} }
if (!connection) if (!connection)
{ {
if (Database.ComparePassword(u, HashCodeModel.GetSHA256Hash(u.Password).ToString()))
if (Database.ComparePassword(u, HashCodeModel.GetSHA256Hash(password).ToString()))
{ {
u.IsConnected = true; u.IsConnected = true;
Console.WriteLine("\nConnection réussie !\n"); Console.WriteLine("\nConnection réussie !\n");
menu = false; menu = false;
break;
} }
else else
{ {
@ -206,6 +211,8 @@ while (arreter)
connection = Choix_DefaultNon(); connection = Choix_DefaultNon();
} }
//inscription //inscription
while (inscription) while (inscription)
{ {
@ -258,6 +265,10 @@ while (arreter)
{ {
case "1": case "1":
note = true; note = true;
foreach (Note notetodisplay in u.NoteList)
{
Console.WriteLine("- " + notetodisplay.Name);
}
break; break;
case "2": case "2":
tags = true; tags = true;
@ -266,6 +277,7 @@ while (arreter)
para = true; para = true;
break; break;
case "4": case "4":
menu = true;
Console.WriteLine("\ndéconnecté! \n"); Console.WriteLine("\ndéconnecté! \n");
u.IsConnected = false; u.IsConnected = false;
u = uvide; u = uvide;
@ -277,10 +289,6 @@ while (arreter)
while (note) while (note)
{ {
foreach (Note notetodisplay in u.NoteList)
{
Console.WriteLine( "- " + notetodisplay.Name);
}
Console.WriteLine("\n|--------------------------------------|"); Console.WriteLine("\n|--------------------------------------|");
Console.WriteLine("| |"); Console.WriteLine("| |");
Console.WriteLine("| menu - note |"); Console.WriteLine("| menu - note |");
@ -566,13 +574,6 @@ while (arreter)
} }
break; break;
case "13": 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<Note> wantedNotes = new List<Note>(); List<Note> wantedNotes = new List<Note>();
Console.WriteLine("\nEntrez le nom de la note à rechercher :"); Console.WriteLine("\nEntrez le nom de la note à rechercher :");
@ -656,6 +657,7 @@ while (arreter)
Console.WriteLine("choisissez le tags à rechercher"); Console.WriteLine("choisissez le tags à rechercher");
string? tagstoresearch = Console.ReadLine(); string? tagstoresearch = Console.ReadLine();
if (tagstoresearch == null) { continue; } if (tagstoresearch == null) { continue; }
if (wantedNotes == null) { Console.WriteLine("Aucun resultat !"); break; }
wantedNotes = u.SearchNoteByTag(wantedNotes, tagstoresearch); wantedNotes = u.SearchNoteByTag(wantedNotes, tagstoresearch);
} }
if (wantedNotes == null) { Console.WriteLine("Aucun resultat !"); break; } if (wantedNotes == null) { Console.WriteLine("Aucun resultat !"); break; }
@ -886,11 +888,6 @@ while (arreter)
{ {
u.ChangePassword(wantedNewPassword); u.ChangePassword(wantedNewPassword);
} }
catch(AlreadyExistException ex)
{
Console.WriteLine(ex.Message);
break;
}
catch(NotAllowedException ex) catch(NotAllowedException ex)
{ {
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
@ -1132,4 +1129,4 @@ while (arreter)
} }
} }
} }
manager.SaveDatabaseData(db); //manager.SaveDatabaseData(db);

@ -25,45 +25,32 @@ namespace Notus_Persistance
User uselect; User uselect;
// add some users // 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("Benjamin", "labsent@gmail.com", "Moto2005"));
database.AddUser(new User("Liam", "liammonchanin@gmail.com", "Baguette")); 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 // 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", ""); database.UserList[i].CreateNote($"Note {i}", "DefaultLogo.png");
user.CreateNote("Note 2", ""); database.UserList[i].CreateTag($"Tag {i}", "#5555FF");
user.CreateNote("Note 3", "");
user.CreateTag("Tag 1","#FA0034");
user.CreateTag("Tag 2", "#2500A4");
} }
// add note to user for sharing note test mixed with tag // 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 uselect = database.UserList[0];
database.DefaultLogoList.Add(new Logo("Logo_1", "logo")); nselect = uselect.NoteList[0];
database.DefaultLogoList.Add(new Logo("Logo_2", "logo")); nselect.AddCollaborator(uselect, database.UserList[1]);
database.DefaultLogoList.Add(new Logo("Logo_3", "logo")); nselect.AddCollaborator(uselect, database.UserList[2]);
List<string> colorListHexaCode = new("FF0000,00FF00,0000FF".Split(',')); uselect.AddTagFromNoteList(nselect, uselect.TagList[0]);
database.AddTheme(new Theme("Theme_1", colorListHexaCode)); nselect.AddEditor(uselect, database.UserList[2]);
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));
// add some default logos and themes
foreach (User user in database.UserList) foreach (User user in database.UserList)
{ {
user.ChangePassword(HashCodeModel.GetSHA256Hash(user.Password).ToString()); user.ChangePassword(user.Password);
} }
return database; return database;
@ -71,11 +58,18 @@ namespace Notus_Persistance
public List<Theme> LoadDefaultTheme() public List<Theme> LoadDefaultTheme()
{ {
throw new NotImplementedException(); List<Theme> DefaultThemeList = new List<Theme>();
DefaultThemeList.Add(new("blacktheme", "#000000,#FF00FF,#OOFFOO".Split().ToList()));
DefaultThemeList.Add(new("whitetheme", "#FFFFFF,#FF00FF,#OOFFOO".Split().ToList()));
return DefaultThemeList;
} }
public List<Logo> LoadDefaultLogo() public List<Logo> LoadDefaultLogo()
{ {
throw new NotImplementedException(); List<Logo> DefaultLogoList = new List<Logo>();
DefaultLogoList.Add(new("default","DefaultLogo.png"));
DefaultLogoList.Add(new("1", "Logo1.png"));
DefaultLogoList.Add(new("2", "Logo2.png"));
return DefaultLogoList;
} }
} }

Loading…
Cancel
Save