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.
Projet_IHM/Sources/Stim/Create.xaml.cs

42 lines
2.2 KiB

using Microsoft.Maui.Graphics;
using System.Text.RegularExpressions;
namespace Stim;
public partial class Create : ContentPage
{
public Create()
{
InitializeComponent();
}
private async void Creer_un_compte(object sender, EventArgs e)
{
Error.Clear();
if (!(string.IsNullOrWhiteSpace(Username.Text) || string.IsNullOrWhiteSpace(Pswd.Text) || string.IsNullOrWhiteSpace(Email.Text)))
{
if (((App)App.Current).Manager.SearchUser(Username.Text) == null)
{
GeneratedRegexAttribute rg = new GeneratedRegexAttribute("^([a-zA-Z0-9_.])+@([a-zA-Z0-9_]+[.])+[a-zA-Z0-9_]{2,}$");
if (rg.Match(Email.Text))
{
rg = new GeneratedRegexAttribute("^(?=.*[A-Za-z])(?=.*[0-9@$!%*#?&])[A-Za-z-0-9@$!%*#?&]{8,}$");
if (rg.Match(Pswd.Text))
{
((App)App.Current).Manager.AddUsertoUserList(new("", Username.Text, "", Email.Text, Pswd.Text));
((App)App.Current).Manager.CurrentUser = ((App)App.Current).Manager.SearchUser(Username.Text);
Application.Current.MainPage = new AppShell();
await Shell.Current.GoToAsync("//MainPage");
}
else Error.Children.Add(new Label { Text = "Mot de passe invalide, votre mot de passe doit contenir une Majuscule, une minuscule, un chiffre et faire au moins 8 caractères", TextColor = Colors.Red, VerticalTextAlignment = TextAlignment.Start });
}
else Error.Children.Add(new Label { Text = "Email invalide", TextColor = Colors.Red, VerticalTextAlignment = TextAlignment.Start });
}
else Error.Children.Add(new Label { Text = "Ce nom d'utilisateur est déjà pris", TextColor = Colors.Red, VerticalTextAlignment = TextAlignment.Start });
}
else Error.Children.Add(new Label { Text = "Champs vides", TextColor = Colors.Red, VerticalTextAlignment = TextAlignment.Start });
}
private void Se_connecter(object sender, EventArgs e)
{
Application.Current.MainPage = new LoginPage();
}
}