From fdca99b5890451dbff448707ab80e62d0d14ddd4 Mon Sep 17 00:00:00 2001 From: Maxime BATISTA Date: Fri, 26 May 2023 10:36:03 +0200 Subject: [PATCH] add nullchecks for user's entry in login and register pages --- Controllers/ConnectionController.cs | 25 +++++++++++++++++++++++++ Views/CreateRecipePage.xaml.cs | 8 ++++---- Views/FavoritesPage.xaml.cs | 4 ++-- Views/HomePage.xaml.cs | 5 +---- Views/LoginPage.xaml.cs | 2 +- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Controllers/ConnectionController.cs b/Controllers/ConnectionController.cs index 5958a6a..8d1ebb8 100644 --- a/Controllers/ConnectionController.cs +++ b/Controllers/ConnectionController.cs @@ -14,6 +14,16 @@ namespace ShoopNCook.Controllers public void Login(string email, string password) { + if (email == null) + { + UserNotifier.Notice("Please provide an email address"); + return; + } + if (password == null) + { + UserNotifier.Notice("Please provide your password"); + return; + } Account? acc = accounts.Login(email, password); if (acc == null) { @@ -25,6 +35,21 @@ namespace ShoopNCook.Controllers public void Register(string username, string email, string password) { + if (email == null) + { + UserNotifier.Notice("Please provide an email address"); + return; + } + if (password == null) + { + UserNotifier.Notice("Please provide your password"); + return; + } + if (username == null) + { + UserNotifier.Notice("Please provide an username"); + return; + } Account? acc = accounts.Register(username, email, password); if (acc == null) { diff --git a/Views/CreateRecipePage.xaml.cs b/Views/CreateRecipePage.xaml.cs index f39d3f7..d5bf8ec 100644 --- a/Views/CreateRecipePage.xaml.cs +++ b/Views/CreateRecipePage.xaml.cs @@ -16,21 +16,21 @@ public partial class CreateRecipePage : ContentPage this.onRecipeCreated = onRecipeCreated; } - private async void OnAddIngredientTapped(object sender, TappedEventArgs e) + private void OnAddIngredientTapped(object sender, TappedEventArgs e) { IngredientList.Children.Add(new IngredientEntry()); } - private async void OnAddStepTapped(object sender, TappedEventArgs e) + private void OnAddStepTapped(object sender, TappedEventArgs e) { StepList.Children.Add(new StepEntry((uint) StepList.Children.Count() + 1)); } private async void OnBackButtonClicked(object sender, EventArgs e) { - Navigation.PopAsync(); + await Navigation.PopAsync(); } - private async void OnUploadRecipeClicked(object sender, EventArgs e) + private void OnUploadRecipeClicked(object sender, EventArgs e) { uint callPerPers; diff --git a/Views/FavoritesPage.xaml.cs b/Views/FavoritesPage.xaml.cs index 4bdda6e..9bf6cae 100644 --- a/Views/FavoritesPage.xaml.cs +++ b/Views/FavoritesPage.xaml.cs @@ -29,13 +29,13 @@ public partial class FavoritesPage : ContentPage { RecipeViewLayout.Children.Add(new RecipeView(info, async () => { - Recipe? recipe = service.GetRecipe(info); + Recipe recipe = service.GetRecipe(info); await Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); })); }); } - private async void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e) + private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e) { UpdateFavorites(); } diff --git a/Views/HomePage.xaml.cs b/Views/HomePage.xaml.cs index f38fb0f..e4b1233 100644 --- a/Views/HomePage.xaml.cs +++ b/Views/HomePage.xaml.cs @@ -19,7 +19,7 @@ public partial class HomePage : ContentPage { layout.Children.Add(new RecipeView(info, () => { - Recipe? recipe = service.GetRecipe(info); + Recipe recipe = service.GetRecipe(info); if (recipe != null) Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); else @@ -36,9 +36,6 @@ public partial class HomePage : ContentPage ProfilePictureName.Text = account.User.Name; } - - - private async void OnSyncButtonClicked(object sender, EventArgs e) { await Shell.Current.Navigation.PushAsync(new SearchPage()); diff --git a/Views/LoginPage.xaml.cs b/Views/LoginPage.xaml.cs index 6d2293a..c3eaeb8 100644 --- a/Views/LoginPage.xaml.cs +++ b/Views/LoginPage.xaml.cs @@ -11,7 +11,7 @@ public partial class LoginPage : ContentPage InitializeComponent(); this.controller = controller; } - private async void OnLoginButtonClicked(object sender, EventArgs e) + private void OnLoginButtonClicked(object sender, EventArgs e) { string email = EmailEntry.Text; string password = PasswordEntry.Text;