diff --git a/MangaMap/App.xaml.cs b/MangaMap/App.xaml.cs index f852825..f247bfb 100644 --- a/MangaMap/App.xaml.cs +++ b/MangaMap/App.xaml.cs @@ -18,7 +18,7 @@ public partial class App : Application MyManager.Admins.Add(MyAdmin); MainPage = new AppShell(); - //MyManager.Persistance = new DataContract(); + MyManager.Persistance = new DataContract(); MyManager.sauvegarder(); } diff --git a/MangaMap/AppShell.xaml b/MangaMap/AppShell.xaml index a967bf5..20d839e 100644 --- a/MangaMap/AppShell.xaml +++ b/MangaMap/AppShell.xaml @@ -7,9 +7,15 @@ xmlns:Views="clr-namespace:MangaMap.Views" Shell.FlyoutBehavior="Disabled" Shell.NavBarIsVisible="False" - Shell.TabBarIsVisible="False"> + Shell.TabBarIsVisible="True"> + + + @@ -104,3 +105,114 @@ +======= + + + + net7.0-android;net7.0-ios;net7.0-maccatalyst + $(TargetFrameworks);net7.0-windows10.0.19041.0 + + + Exe + MangaMap + true + true + enable + + + MangaMap + + + com.companyname.mangamap + 61196d0c-418f-4fb6-8dc5-c920275e1035 + + + 1.0 + 1 + + 11.0 + 13.1 + 21.0 + 10.0.17763.0 + 10.0.17763.0 + 6.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CustomHeader.xaml + + + signUpPage.xaml + + + + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + + +>>>>>>> Mathéo diff --git a/MangaMap/Stub/DataContract.cs b/MangaMap/Stub/DataContract.cs index 9f49598..f2d0f3e 100644 --- a/MangaMap/Stub/DataContract.cs +++ b/MangaMap/Stub/DataContract.cs @@ -1,62 +1,82 @@ -using MangaMap.Model; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; -using System.Xml; - -namespace MangaMap.Stub -{ - public class DataContract : IPersistanceManager - { - public string FileName { get; set; } = "SauvegardeDonnees.xml"; - public string FilePath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory); - //public string FilePath2 { get; set; } = "C:\\Users\\vjour\\UCA\\MapManga\\MangaMap"; - //public string FilePath2 { get; set; } = Path.Combine(Directory.GetCurrentDirectory(), "\\..\\..\\Users"); - - public (List, List) chargeDonne() - { - var serializer = new DataContractSerializer(typeof(DataToPersist)); - DataToPersist data; - - using (Stream s = File.OpenRead(Path.Combine(FilePath, FileName))) - { - data = serializer.ReadObject(s) as DataToPersist; - } - - return (data.Oeuvres, data.Utilisateurs); - } - - public void sauvegarder(List o, List u) - { - var serializer = new DataContractSerializer(typeof(DataToPersist)); - - if(!Directory.Exists(FilePath)) - { - Debug.WriteLine("Directory doesn't exist."); - Directory.CreateDirectory(FilePath); - } - - /*using (Stream s = File.Create(Path.Combine(FilePath, FileName))) - { - serializer.WriteObject(s, o); //Version d'enregistrement des données sans indentation. - }*/ - - DataToPersist data = new DataToPersist(); - data.Oeuvres = o; - data.Utilisateurs = u; - - var settings = new XmlWriterSettings() { Indent = true }; - using (TextWriter tw = File.CreateText(Path.Combine(FilePath, FileName))) - { - using (XmlWriter w = XmlWriter.Create(tw, settings)) - { - serializer.WriteObject(w, data); //Version d'enregistrement des données avec indentation. - } - } - } - } +using MangaMap.Model; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + + +namespace MangaMap.Stub +{ + public class DataContract : IPersistanceManager + { + public string FileName { get; set; } = "SauvegardeDonnees.xml"; + public string FilePath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory); + + public (List, List) chargeDonne() + { + var serializer = new DataContractSerializer(typeof(DataToPersist)); + DataToPersist data; + + if (File.Exists(Path.Combine(FilePath, FileName))) // Vérifiez si le fichier existe + { + using (Stream s = File.OpenRead(Path.Combine(FilePath, FileName))) + { + data = serializer.ReadObject(s) as DataToPersist; + } + } + else + { + data = new DataToPersist(); // Si le fichier n'existe pas, créez une nouvelle liste + } + + return (data.Oeuvres, data.Utilisateurs); + } + + public void sauvegarder(List o, List u) + { + var serializer = new DataContractSerializer(typeof(DataToPersist)); + + DataToPersist data; + if (File.Exists(Path.Combine(FilePath, FileName))) + { + using (Stream s = File.OpenRead(Path.Combine(FilePath, FileName))) + { + data = serializer.ReadObject(s) as DataToPersist; + } + } + else + { + data = new DataToPersist(); + } + + // Vérifier si un utilisateur avec le même nom d'utilisateur existe déjà + var existingUser = data.Utilisateurs.FirstOrDefault(user => user.Pseudo == u.Last().Pseudo); + if (existingUser != null) + { + // Mettre à jour l'utilisateur existant + existingUser.MotDePasse = u.Last().MotDePasse; + existingUser.Email = u.Last().Email; + + } + else + { + // Ajouter le nouvel utilisateur à la liste existante + data.Utilisateurs.Add(u.Last()); + } + + var settings = new XmlWriterSettings() { Indent = true }; + using (TextWriter tw = File.CreateText(Path.Combine(FilePath, FileName))) + { + using (XmlWriter w = XmlWriter.Create(tw, settings)) + { + serializer.WriteObject(w, data); // Enregistrer toutes les données dans le fichier + } + } + } + } + } \ No newline at end of file diff --git a/MangaMap/Views/homePage.xaml.cs b/MangaMap/Views/homePage.xaml.cs index c8a9da0..e454b1e 100644 --- a/MangaMap/Views/homePage.xaml.cs +++ b/MangaMap/Views/homePage.xaml.cs @@ -12,4 +12,5 @@ public partial class homePage : ContentPage a1.BindingContext = my_manager; a2.BindingContext = my_manager; } -} \ No newline at end of file +} + diff --git a/MangaMap/Views/homePageDisconnect.xaml b/MangaMap/Views/homePageDisconnect.xaml new file mode 100644 index 0000000..f528f92 --- /dev/null +++ b/MangaMap/Views/homePageDisconnect.xaml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MangaMap/Views/homePageDisconnect.xaml.cs b/MangaMap/Views/homePageDisconnect.xaml.cs new file mode 100644 index 0000000..28cf76e --- /dev/null +++ b/MangaMap/Views/homePageDisconnect.xaml.cs @@ -0,0 +1,9 @@ +namespace MangaMap.Views; + +public partial class homePageDisconnect : ContentPage +{ + public homePageDisconnect() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/MangaMap/Views/loginPage.xaml.cs b/MangaMap/Views/loginPage.xaml.cs index 8ab881b..b69c351 100644 --- a/MangaMap/Views/loginPage.xaml.cs +++ b/MangaMap/Views/loginPage.xaml.cs @@ -1,10 +1,13 @@ namespace MangaMap.Views; using System.Text.RegularExpressions; using System.Threading.Tasks; +using MangaMap.Stub; +using MangaMap.Model; public partial class loginPage : ContentPage + { - public loginPage() + public loginPage() { InitializeComponent(); } @@ -25,18 +28,32 @@ public partial class loginPage : ContentPage // Vérifier que l'e-mail a la bonne forme if (!Regex.IsMatch(email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$")) { - await DisplayAlert("Erreur", "L'e-mail n'est pas valide.", "OK"); + await DisplayAlert("Erreur", "L'email n'est pas valide.", "OK"); return; } - // Vérification du mot de passe - if (password != "monmotdepasse") + // Charger les données à partir de la persistance + IPersistanceManager persistanceManager = new DataContract(); + (List oeuvres, List utilisateurs) = persistanceManager.chargeDonne(); + + // Vérifier que l'utilisateur existe + Utilisateur utilisateur = utilisateurs.FirstOrDefault(u => u.Email == email && u.MotDePasse == password); + if (utilisateur == null) { +<<<<<<< HEAD await DisplayAlert("Erreur", "Le mot de passe entré est incorrect.", "OK"); return; } // Redirection vers la page suivante si le mot de passe est correct +======= + await DisplayAlert("Erreur", "L'e-mail ou le mot de passe est incorrect.", "OK"); + return; + } + + // Rediriger l'utilisateur vers la page principale +>>>>>>> Mathéo await Navigation.PushAsync(new homePage()); } + } diff --git a/MangaMap/Views/settingsPage.xaml b/MangaMap/Views/settingsPage.xaml index dd77c2f..f0060ba 100644 --- a/MangaMap/Views/settingsPage.xaml +++ b/MangaMap/Views/settingsPage.xaml @@ -10,7 +10,7 @@ -