From 5abc2e945a6e13b8e5793d4cad1659f63aecf4fe Mon Sep 17 00:00:00 2001 From: Jade_VAN_BRABANDT Date: Tue, 6 Jun 2023 16:30:45 +0200 Subject: [PATCH 1/8] Feat : BindingProperty popup =>Marche pas sur contentview ? --- Sources/Stim.Model/User.cs | 9 ++--- Sources/Stim/EntryPopup.xaml | 1 + Sources/Stim/EntryPopup.xaml.cs | 5 +-- Sources/Stim/ProfilPage.xaml | 26 +++++---------- Sources/Stim/UserInfo.xaml | 7 ++-- Sources/Stim/UserInfo.xaml.cs | 59 +++++++++++++++++++++++++++------ 6 files changed, 70 insertions(+), 37 deletions(-) diff --git a/Sources/Stim.Model/User.cs b/Sources/Stim.Model/User.cs index 9988a45..553e3f8 100644 --- a/Sources/Stim.Model/User.cs +++ b/Sources/Stim.Model/User.cs @@ -11,7 +11,7 @@ namespace Model public sealed class User : INotifyPropertyChanged , IEquatable { [DataMember] - public string? Username + public string Username { get => username; set @@ -29,7 +29,7 @@ namespace Model public string Biographie { get => biographie ?? "Pas de biographie"; - private set + set { if (string.IsNullOrWhiteSpace(value)) biographie = "Pas de biographie"; else @@ -44,7 +44,7 @@ namespace Model public string Email { get => email; - private set + set { Regex rg_email = new Regex("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"); if (!(string.IsNullOrWhiteSpace(value)) && rg_email.IsMatch(value)) @@ -60,7 +60,7 @@ namespace Model public string Password { get => password; - private set + set { Regex rg = new Regex("^(?=.*[A-Za-z])(?=.*[0-9@$!%*#?&])[A-Za-z-0-9@$!%*#?&]{8,}$"); if (string.IsNullOrWhiteSpace(value) || !rg.IsMatch(value)) throw new ArgumentNullException(value); @@ -167,5 +167,6 @@ namespace Model foreach (Game game in Followed_Games) builder.Append($"{game.Name}\n"); return builder.ToString(); } + } } diff --git a/Sources/Stim/EntryPopup.xaml b/Sources/Stim/EntryPopup.xaml index b8b9542..bc09522 100644 --- a/Sources/Stim/EntryPopup.xaml +++ b/Sources/Stim/EntryPopup.xaml @@ -10,6 +10,7 @@ - - - - - - - - - - - + + diff --git a/Sources/Stim/UserInfo.xaml b/Sources/Stim/UserInfo.xaml index dca8861..047b2f0 100644 --- a/Sources/Stim/UserInfo.xaml +++ b/Sources/Stim/UserInfo.xaml @@ -10,9 +10,12 @@ - - + - - + + diff --git a/Sources/Stim/ProfilPage.xaml.cs b/Sources/Stim/ProfilPage.xaml.cs index 20f6dff..e972262 100644 --- a/Sources/Stim/ProfilPage.xaml.cs +++ b/Sources/Stim/ProfilPage.xaml.cs @@ -5,6 +5,7 @@ namespace Stim; public partial class ProfilPage : ContentPage { + delegate string delegatePopUp(); public ProfilPage() { InitializeComponent(); @@ -22,4 +23,8 @@ public partial class ProfilPage : ContentPage if (string.IsNullOrWhiteSpace(newName as string)) await this.ShowPopupAsync(new MessagePopup("Nom d'utilisateur invalide")); else ((App)App.Current).Manager.CurrentUser.Username = (newName as string); } + void PopUp(object sender, EventArgs e) + { + //handle method here + } } \ No newline at end of file diff --git a/Sources/Stim/UserInfo.xaml b/Sources/Stim/UserInfo.xaml index 047b2f0..1611420 100644 --- a/Sources/Stim/UserInfo.xaml +++ b/Sources/Stim/UserInfo.xaml @@ -10,12 +10,12 @@ - - - - + + + + diff --git a/Sources/Stim/ProfilPage.xaml.cs b/Sources/Stim/ProfilPage.xaml.cs index e972262..1b26846 100644 --- a/Sources/Stim/ProfilPage.xaml.cs +++ b/Sources/Stim/ProfilPage.xaml.cs @@ -1,11 +1,11 @@ using CommunityToolkit.Maui.Views; using Model; +using System.Text.RegularExpressions; namespace Stim; public partial class ProfilPage : ContentPage { - delegate string delegatePopUp(); public ProfilPage() { InitializeComponent(); @@ -23,8 +23,29 @@ public partial class ProfilPage : ContentPage if (string.IsNullOrWhiteSpace(newName as string)) await this.ShowPopupAsync(new MessagePopup("Nom d'utilisateur invalide")); else ((App)App.Current).Manager.CurrentUser.Username = (newName as string); } - void PopUp(object sender, EventArgs e) + public async void PopUpUsername(object sender, EventArgs e) { - //handle method here + var newName = await this.ShowPopupAsync(new EntryPopup("Username")); + if (string.IsNullOrWhiteSpace(newName as string)) await this.ShowPopupAsync(new MessagePopup("Nom d'utilisateur invalide")); + else ((App)App.Current).Manager.CurrentUser.Username = (newName as string); + } + public async void PopUpBio(object sender, EventArgs e) + { + var newBio = await this.ShowPopupAsync(new EntryPopup("Biographie")); + ((App)App.Current).Manager.CurrentUser.Biographie = (newBio as string); + } + public async void PopUpPswd(object sender, EventArgs e) + { + Regex rg = new Regex("^(?=.*[A-Za-z])(?=.*[0-9@$!%*#?&])[A-Za-z-0-9@$!%*#?&]{8,}$"); + var newPswd = await this.ShowPopupAsync(new EntryPopup("Password")); + if (string.IsNullOrWhiteSpace(newPswd as string) || rg.IsMatch(newPswd as string)) await this.ShowPopupAsync(new MessagePopup("Nom d'utilisateur invalide")); + else ((App)App.Current).Manager.CurrentUser.Password = (newPswd as string); + } + public async void PopUpEmail(object sender, EventArgs e) + { + Regex rg = new Regex("^([a-zA-Z0-9_-]+[.])*[a-zA-Z0-9_-]+@([a-zA-Z0-9_-]+[.])+[a-zA-Z0-9_-]{2,4}$"); + var newMail = await this.ShowPopupAsync(new EntryPopup("Email")); + if (string.IsNullOrWhiteSpace(newMail as string) || rg.IsMatch(newMail as string)) await this.ShowPopupAsync(new MessagePopup("Email Invalide")); + else ((App)App.Current).Manager.CurrentUser.Email = (newMail as string); } } \ No newline at end of file diff --git a/Sources/Stim/UserInfo.xaml b/Sources/Stim/UserInfo.xaml index 1611420..2349dba 100644 --- a/Sources/Stim/UserInfo.xaml +++ b/Sources/Stim/UserInfo.xaml @@ -9,10 +9,10 @@ - -