From dd93267af836243f8745b00591334f2e990517e6 Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Wed, 7 Jun 2023 18:44:45 +0200 Subject: [PATCH] first login working --- MCTG/Views/ContentPages/Home.xaml.cs | 2 +- MCTG/Views/ContentPages/Login.xaml.cs | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/MCTG/Views/ContentPages/Home.xaml.cs b/MCTG/Views/ContentPages/Home.xaml.cs index 86d2c8c..b2bc72e 100644 --- a/MCTG/Views/ContentPages/Home.xaml.cs +++ b/MCTG/Views/ContentPages/Home.xaml.cs @@ -14,7 +14,7 @@ namespace Views public Home() { - Master.User.LogIn("pedrosamigos@hotmail.com", "pamigos"); + // Master.User.LogIn("pedrosamigos@hotmail.com", "pamigos"); if (Master.User.CurrentConnected is null) { _recipesDisplayed = Master.Recipe.GetAllRecipes(); diff --git a/MCTG/Views/ContentPages/Login.xaml.cs b/MCTG/Views/ContentPages/Login.xaml.cs index 9704af4..ac40aa2 100644 --- a/MCTG/Views/ContentPages/Login.xaml.cs +++ b/MCTG/Views/ContentPages/Login.xaml.cs @@ -1,3 +1,4 @@ +using AppException; using Model; namespace Views; @@ -14,13 +15,29 @@ public partial class Login : ContentPage private void LoginButton_Clicked(object sender, EventArgs e) { - if (!Master.User.LogIn(login_entry.Text, passwd_entry.Text)) + string mail = login_entry.Text; + string password = passwd_entry.Text; + var usermgr = Master.User; + + if (firstLogin_checkbox.IsChecked) { - DisplayAlert("Wrong informations", "No mail or an incorrect password have been entered.", "OK"); + try + { + usermgr.AddUserToData(usermgr.CreateUser(mail, password)); + } + catch (BadMailFormatException) + { + DisplayAlert("Bad mail format", "The mail you entered do not respect the format of a mail address.", "Ok"); + return; + } + } + + if (!usermgr.LogIn(mail, password)) + { + DisplayAlert("Wrong informations", "Incorrect mail or password have been entered.", "Ok"); } else { - Navigation.PopModalAsync(); } }