Finalisation de la Connexion. Refonte de la création de jeu par un Admin #54

Merged
remi.lavergne merged 1 commits from remi into master 2 years ago

@ -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 Microsoft.Maui.Controls;
using GameAtlas.Models; using GameAtlas.Models;
using System.Diagnostics;
namespace GameAtlas.Views; namespace GameAtlas.Views;
public partial class PageAdmin : ContentPage public partial class PageAdmin : ContentPage
{ {
public Manager AdminManager => (App.Current as App).MyManager;
public PageAdmin() public PageAdmin()
{ {
InitializeComponent(); InitializeComponent();
} }
/**
* \brief Flèche de retour en arrière
* \return void
*/
async void Back_Tapped(System.Object sender, Microsoft.Maui.Controls.TappedEventArgs e) async void Back_Tapped(System.Object sender, Microsoft.Maui.Controls.TappedEventArgs e)
{ {
await Navigation.PopAsync(); 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) private async void OnButtonClicked(object sender, EventArgs e)
{ {
string nom = await DisplayPromptAsync("Informations sur le Jeu", "Quel est le Titre ?", placeholder: "GTA VI"); 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 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 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 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 note = await DisplayPromptAsync("Informations sur le Jeu", "Note de 0 à 5", maxLength: 1, placeholder: "5");
string nbtelechargement = await DisplayPromptAsync("Informations sur le Jeu", "Nombre de Téléchargements (en milliers, ex: 630k)", keyboard: Keyboard.Numeric, placeholder: "630"); 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 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é.");
} }
} }

@ -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; namespace GameAtlas.Views;
using GameAtlas.Models; using GameAtlas.Models;
@ -6,7 +12,7 @@ using System.Text.RegularExpressions;
public partial class PageConnexion : ContentPage public partial class PageConnexion : ContentPage
{ {
public int compteur { get; set; } = 0; private bool connexionWorked;
public Manager ConnexionManager => (App.Current as App).MyManager; public Manager ConnexionManager => (App.Current as App).MyManager;
public PageConnexion() public PageConnexion()
@ -14,6 +20,11 @@ public partial class PageConnexion : ContentPage
InitializeComponent(); 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) private async void OnSignInClicked(object sender, EventArgs e)
{ {
@ -27,16 +38,28 @@ public partial class PageConnexion : ContentPage
return; return;
} }
Verification(username, password); connexionWorked = Verification(username, password);
if (connexionWorked)
{
await Navigation.PushAsync(new PageAcceuil()); 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) private async void OnInscrire_Tapped(object sender, EventArgs e)
{ {
await Navigation.PushAsync(new PageInscription()); 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) private async void OnMotDePasseOublie_Tapped(object sender, EventArgs e)
{ {
await DisplayAlert("Oh non !", "Le mot de passe va te revenir à force", "Concentration"); 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) public bool Verification(string username, string password)
{ {
foreach (Utilisateur user in ConnexionManager.Utilisateurs) 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)"); 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; ConnexionManager.ConnectedUser = null;
return false; return false;
} }

@ -35,6 +35,8 @@ public partial class PageJeu : ContentPage
if (action == "Mes Favoris") 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); JeuManager.ConnectedUser.ListeFavoris.Add(JeuModel);
} }

Loading…
Cancel
Save