From f732a442048d3a3d18f69f5ada8f0991feb92c83 Mon Sep 17 00:00:00 2001 From: "remi.lavergne" Date: Thu, 1 Jun 2023 15:12:07 +0200 Subject: [PATCH] =?UTF-8?q?Finalisation=20de=20la=20Connexion.=20Refonte?= =?UTF-8?q?=20de=20la=20cr=C3=A9ation=20de=20jeu=20par=20un=20Admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GameAtlas/GameAtlas/Views/PageAdmin.xaml.cs | 32 +++++++++++++-- .../GameAtlas/Views/PageConnexion.xaml.cs | 40 +++++++++++++++++-- GameAtlas/GameAtlas/Views/PageJeu.xaml.cs | 2 + 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/GameAtlas/GameAtlas/Views/PageAdmin.xaml.cs b/GameAtlas/GameAtlas/Views/PageAdmin.xaml.cs index 16b852a..b61c489 100644 --- a/GameAtlas/GameAtlas/Views/PageAdmin.xaml.cs +++ b/GameAtlas/GameAtlas/Views/PageAdmin.xaml.cs @@ -1,20 +1,38 @@ +/** + * \file PageAdmin.xaml.cs + * \brief Fonctionnalités administrateur + * Code regroupant les fonctionnalités administrateur de l'application (gestion des jeux) + */ + using Microsoft.Maui.Controls; using GameAtlas.Models; +using System.Diagnostics; namespace GameAtlas.Views; public partial class PageAdmin : ContentPage { + public Manager AdminManager => (App.Current as App).MyManager; public PageAdmin() { InitializeComponent(); } + /** + * \brief Flèche de retour en arrière + * \return void + */ async void Back_Tapped(System.Object sender, Microsoft.Maui.Controls.TappedEventArgs e) { await Navigation.PopAsync(); } + /** + * \brief Bouton d'ajout de jeu + * Affiche une succession de pop-up, pour remplir les champs un par un. + * Traitement et vérification des champs. + * \return void + */ private async void OnButtonClicked(object sender, EventArgs e) { string nom = await DisplayPromptAsync("Informations sur le Jeu", "Quel est le Titre ?", placeholder: "GTA VI"); @@ -22,9 +40,17 @@ public partial class PageAdmin : ContentPage string plateformes = await DisplayPromptAsync("Informations sur le Jeu", "Plateforme(s), un espace pour séparer", placeholder: "Ex: XOne PC PS5"); string developpeur = await DisplayPromptAsync("Informations sur le Jeu", "Développeur", placeholder: "Rockstar Games"); string editeur = await DisplayPromptAsync("Informations sur le Jeu", "Editeur", placeholder: "Take-Two Interactive"); - string note = await DisplayPromptAsync("Informations sur le Jeu", "Note de 0 à 5", maxLength: 1, keyboard:Keyboard.Numeric, placeholder: "5"); - string nbtelechargement = await DisplayPromptAsync("Informations sur le Jeu", "Nombre de Téléchargements (en milliers, ex: 630k)", keyboard: Keyboard.Numeric, placeholder: "630"); + string note = await DisplayPromptAsync("Informations sur le Jeu", "Note de 0 à 5", maxLength: 1, placeholder: "5"); + int noteInt = Int32.Parse(note); + string nbTelechargement = await DisplayPromptAsync("Informations sur le Jeu", "Nombre de Téléchargements (en milliers, ex: 630k)", placeholder: "630"); + int nbTelechargementInt = Int32.Parse(nbTelechargement); string genre = await DisplayPromptAsync("Informations sur le Jeu", "Genre(s), un espace pour séparer", placeholder: "Action Aventure"); - string image = await DisplayPromptAsync("Informations sur le Jeu", "Image de couverture (préférez URL finissant par .png)", placeholder: "Take-Two Interactive"); + string image = await DisplayPromptAsync("Informations sur le Jeu", "Image de couverture (préférez URL finissant par .png)", placeholder: "http://example.com/monimage.png"); + + Jeu adminJeu = new Jeu(nom, sortie, plateformes, developpeur, editeur, noteInt, nbTelechargementInt, genre, image); + AdminManager.AddJeux(adminJeu); + AdminManager.SauvegardeDonnees(); + + Debug.WriteLine($"Le jeu \"{adminJeu.Nom}\" a été ajouté."); } } \ No newline at end of file diff --git a/GameAtlas/GameAtlas/Views/PageConnexion.xaml.cs b/GameAtlas/GameAtlas/Views/PageConnexion.xaml.cs index 1fae4f0..4936d9a 100644 --- a/GameAtlas/GameAtlas/Views/PageConnexion.xaml.cs +++ b/GameAtlas/GameAtlas/Views/PageConnexion.xaml.cs @@ -1,3 +1,9 @@ +/** + * \file PageConnexion.xaml.cs + * \brief Système de connexion + * Système de connexion avec vérification et chargement de l'utilisateur connecté + */ + namespace GameAtlas.Views; using GameAtlas.Models; @@ -6,7 +12,7 @@ using System.Text.RegularExpressions; public partial class PageConnexion : ContentPage { - public int compteur { get; set; } = 0; + private bool connexionWorked; public Manager ConnexionManager => (App.Current as App).MyManager; public PageConnexion() @@ -14,6 +20,11 @@ public partial class PageConnexion : ContentPage InitializeComponent(); } + /** + * \brief Bouton "Connexion" + * Réaction au clic sur le bouton, vérification des champs non vide. + * \return void + */ private async void OnSignInClicked(object sender, EventArgs e) { @@ -27,16 +38,28 @@ public partial class PageConnexion : ContentPage return; } - Verification(username, password); - await Navigation.PushAsync(new PageAcceuil()); - + connexionWorked = Verification(username, password); + if (connexionWorked) + { + await Navigation.PushAsync(new PageAcceuil()); + } } + /** + * \brief Texte "S'inscrire" + * Réaction au clic sur le texte, envoie sur le page d'Inscription. + * \return void + */ private async void OnInscrire_Tapped(object sender, EventArgs e) { await Navigation.PushAsync(new PageInscription()); } + /** + * \brief Texte "Mot de Passe oublié" + * Réaction au clic sur le texte, affichage de pop-ups. + * \return void + */ private async void OnMotDePasseOublie_Tapped(object sender, EventArgs e) { await DisplayAlert("Oh non !", "Le mot de passe va te revenir à force", "Concentration"); @@ -53,6 +76,14 @@ public partial class PageConnexion : ContentPage } } + /** + * \brief Vérification et Chargement + * Vérification de la présence de l'utilisateur dans la Liste d'Utilisateurs. + * Si c'est le cas, comparaison du mot de passe fournis par celui de l'utilisateur. + * Si tout est bon, chargement de l'utilisateur dans ConnectedUser. + * Dans le cas contraire, on renvoie un message d'erreur et termine la vérification. + * \return bool true si la connexion a fonctionnée, false sinon. + */ public bool Verification(string username, string password) { foreach (Utilisateur user in ConnexionManager.Utilisateurs) @@ -69,6 +100,7 @@ public partial class PageConnexion : ContentPage } } Debug.WriteLine("La connection a echouée (pseudo ou mot de passe invalide)"); + DisplayAlert("Erreur", "Utilisateur ou Mot de Passe invalide.", "Ok"); ConnexionManager.ConnectedUser = null; return false; } diff --git a/GameAtlas/GameAtlas/Views/PageJeu.xaml.cs b/GameAtlas/GameAtlas/Views/PageJeu.xaml.cs index acef4df..a261afd 100644 --- a/GameAtlas/GameAtlas/Views/PageJeu.xaml.cs +++ b/GameAtlas/GameAtlas/Views/PageJeu.xaml.cs @@ -35,6 +35,8 @@ public partial class PageJeu : ContentPage if (action == "Mes Favoris") { + Debug.WriteLine(JeuManager.ConnectedUser.Pseudo); + // On dirait que le Bug est causé car même si on est connecté, ConnectedUser = null. JeuManager.ConnectedUser.ListeFavoris.Add(JeuModel); }