You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.9 KiB
68 lines
2.9 KiB
using CommunityToolkit.Maui.Views;
|
|
using Model;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Stim;
|
|
|
|
public partial class ProfilPage : ContentPage
|
|
{
|
|
public ProfilPage()
|
|
{
|
|
InitializeComponent();
|
|
BindingContext = ((App)App.Current).Manager;
|
|
}
|
|
|
|
private void CollectionView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
((App)App.Current).Manager.CurrentUser.RemoveAGame((sender as CollectionView).SelectedItem as Game);
|
|
((App)App.Current).Manager.SaveUser();
|
|
}
|
|
|
|
|
|
public async void PopUpUsername(object sender, EventArgs e)
|
|
{
|
|
var newName = await this.ShowPopupAsync(new EntryPopup("Username"));
|
|
if (string.IsNullOrWhiteSpace(newName as string)) await this.ShowPopupAsync(new MessagePopup("Nom d'utilisateur invalide"));
|
|
else
|
|
{
|
|
if (((App)App.Current).Manager.SearchUser(newName as string) is User)
|
|
{
|
|
await this.ShowPopupAsync(new MessagePopup("Nom d'utilisateur déjà utilisé"));
|
|
}
|
|
else
|
|
{
|
|
string oldName = ((App)App.Current).Manager.CurrentUser.Username;
|
|
((App)App.Current).Manager.CurrentUser.Username = (newName as string);
|
|
foreach (Game g in ((App)App.Current).Manager.GameList)
|
|
{
|
|
foreach(Review r in g.Reviews)
|
|
{
|
|
if (r.AuthorName==oldName as string)
|
|
{
|
|
r.AuthorName= 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("Mot de passe 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);
|
|
}
|
|
} |