private async void GoRegister(object sender, EventArgs e) { LoadIndicator.IsRunning = true; RegBtn.IsEnabled = false; // Perform await function call to id User newUser = new User() { Name = usernameEntry.Text, Email = emailEntry.Text.ToLower(), Password = passwordEntry.Text, Photo = img == true?userUri:"", Phone = phoneEntry.Text, Address = addressEntry.Text, Date = DateTime.Now }; bool res = true; List <User> users = await AzureManager.AzureManagerInstance.GetUsers(); if (users.Where(s => s.Email == newUser.Email).Count() > 0) // User exists { await DisplayAlert("User exists", "User with specified email exists", "OK"); LoadIndicator.IsRunning = false; return; } if (newUser.Password == null || newUser.Name == null || newUser.Email == null) { await DisplayAlert("Incomplete Information", "Please complete the required* fields", "OK"); res = false; } else if (newUser.Password.Length < 1 || newUser.Name.Length < 1 || newUser.Email.Length < 1) { await DisplayAlert("Incomplete Information", "Please complete the required* fields", "OK"); res = false; } if (passwordEntry.Text != passwordEntry2.Text) { await DisplayAlert("Password Mismatch", "Please make sure password fields match", "OK"); res = false; } if (res) { await AzureManager.AzureManagerInstance.AddUser(newUser); await DisplayAlert("Success", "You have been registered to Fabrikam", "OK"); MenuPage.GoHomeAfterLogin(newUser); } RegBtn.IsEnabled = true; LoadIndicator.IsRunning = false; }
private async void GoLogin(object sender, EventArgs e) { LoadIndicator.IsRunning = true; loginBtn.IsEnabled = false; if (emailEntry.Text != null && passwordEntry.Text != null && emailEntry.Text.Length > 0 && passwordEntry.Text.Length > 0) { List <User> users = await AzureManager.AzureManagerInstance.GetUsers(); if (users.Where(s => s.Email == emailEntry.Text.ToLower() && s.Password == passwordEntry.Text).Count() > 0) { await DisplayAlert("Login Succesfull", "Successfilly logged in!", "OK"); MenuPage.GoHomeAfterLogin(users.Where(s => s.Email == emailEntry.Text.ToLower() && s.Password == passwordEntry.Text).ToArray()[0]); } else { await DisplayAlert("Login Failed", "Please login with valid credentials", "OK"); } LoadIndicator.IsRunning = false; } else { await DisplayAlert("Login Failed", "Please fill in the required fields", "OK"); } loginBtn.IsEnabled = true; LoadIndicator.IsRunning = false; }
private void Change(object sender, EventArgs e) { Label passLbl = new Label { Text = "Enter curent password:"******"Password*", IsPassword = true }; Entry pass2 = new Entry { Placeholder = "Current Password*", IsPassword = true }; Button confirm = new Button { Text = "Confirm", TextColor = Color.White, BackgroundColor = Color.Green, Font = Font.SystemFontOfSize(NamedSize.Large), BorderWidth = 1, HorizontalOptions = LayoutOptions.StartAndExpand, }; confirm.Clicked += async(sender2, e2) => { if (pass1.Text == null || pass2.Text == null || pass1.Text.Length < 1 || pass2.Text.Length < 1) { await DisplayAlert("Incomplete Information", "Please complete the password fields", "OK"); } else if (pass1.Text != pass2.Text) { await DisplayAlert("Password mismatch error", "Please enter identical passwords in the displayed fields", "OK"); } else if (pass1.Text != User.CurrentUserInstance.Password) { await DisplayAlert("Password Incorrect", "Please enter correct current password", "OK"); } else { // CHECK IF USER WITH SAME EMAIL EXISTS TO PREVENT CLASHES/DUPLICATES User changedUser = new User() { ID = User.CurrentUserInstance.ID, Name = usernameEntry.Text ?? User.CurrentUserInstance.Name, Email = (emailEntry.Text == null || emailEntry.Text.Length < 1) ? User.CurrentUserInstance.Email : emailEntry.Text, Password = (passwordEntry.Text == null || passwordEntry.Text.Length < 1) ? User.CurrentUserInstance.Password : passwordEntry.Text, Photo = User.CurrentUserInstance.Photo, Phone = phoneEntry.Text ?? User.CurrentUserInstance.Phone, Address = addressEntry.Text ?? User.CurrentUserInstance.Address, Date = DateTime.Now }; await AzureManager.AzureManagerInstance.UpdateUser(changedUser); await DisplayAlert("SUCCESS", "Successfuly changed your details", "OK"); MenuPage.GoHomeAfterLogin(changedUser); } }; Button goBack = new Button { Text = "Back", TextColor = Color.White, BackgroundColor = Color.Red, Font = Font.SystemFontOfSize(NamedSize.Large), BorderWidth = 1, HorizontalOptions = LayoutOptions.EndAndExpand, }; goBack.Clicked += (sender2, e2) => { MenuPage.ChangePage(MenuPage.pages[5]); }; MenuPage.ChangePage(new NavigationPage(new ContentPage { Content = new StackLayout { Children = { passLbl, pass1, pass2, new Grid { Children = { confirm,goBack } } } } })); }