private async void BtnLogar_Click(object sender, EventArgs e) { EditText email = FindViewById <EditText>(Resource.Id.txtEmailLogin); EditText senha = FindViewById <EditText>(Resource.Id.txtSenhaLogin); var userEmail = await fireBaseHelper.GetUser(email.Text); TextView txtTeste = FindViewById <TextView>(Resource.Id.textLogado); if (userEmail != null) { var userSenha = await fireBaseHelper.GetSenhaExiste(senha.Text); if (userSenha != null) { PaginaLogado(); } else { txtTeste.Text = "Senha ou Email errado!"; } } else { txtTeste.Text = "Senha ou Email errado!"; } }
private async void Login() { if (CrossConnectivity.Current != null && CrossConnectivity.Current.IsConnected == false) { await App.Current.MainPage.DisplayAlert("Network error", "Please check ur network connection", "OK"); } //null or empty validation, check if Email and Password is null or empty if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password)) { await App.Current.MainPage.DisplayAlert("Empty Value", "Please enter Email and Password", "OK"); } else { var userLogin = await FireBaseHelper.GetUser(Username); if (userLogin != null) { if (Username == this.Username && Password == this.Password) { var tabbedPage = new TabbedPage(); tabbedPage.Children.Add(new RestaurantPage()); //tabbedPage.Children.Add(new UserMapPage()); if (string.IsNullOrEmpty(userLogin.PhoneNumber)) { tabbedPage.Children.Add(new AccountPage(Username, userLogin.Address, emptyPhoneNo)); } else { tabbedPage.Children.Add(new AccountPage(Username, userLogin.Address, userLogin.PhoneNumber)); } tabbedPage.UnselectedTabColor = Color.FromHex("#D18402"); tabbedPage.SelectedTabColor = Color.FromHex("#C03251"); tabbedPage.BarBackgroundColor = Color.FromHex("#FFFFFF"); await App.Current.MainPage.Navigation.PushAsync(tabbedPage); } else { await App.Current.MainPage.DisplayAlert("Login Fail", "Please enter correct Email and Password", "OK"); } } else { await App.Current.MainPage.DisplayAlert("Login Fail", "User not found", "OK"); } } }
//Update user data private async void Update() { try { if (!string.IsNullOrEmpty(Password) && !string.IsNullOrEmpty(Address)) { var isupdate = await FireBaseHelper.UpdateUser(this.Username, this.Password, this.Address, this.PhoneNumber); if (isupdate) { await App.Current.MainPage.DisplayAlert("Update Success", "", "Ok"); var userInfo = await FireBaseHelper.GetUser(this.Username); if (string.IsNullOrEmpty(userInfo.PhoneNumber)) { await App.Current.MainPage.Navigation.PushAsync(new AccountPage(this.Username, this.Address, nullPhoneNumber)); } else { await App.Current.MainPage.Navigation.PushAsync(new AccountPage(this.Username, this.Address, this.PhoneNumber)); } } else { await App.Current.MainPage.DisplayAlert("Error", "Record not update", "Ok"); } } else { await App.Current.MainPage.DisplayAlert("Password and Address Require", "Please Enter your password or address", "Ok"); } } catch (Exception e) { Debug.WriteLine($"Error:{e}"); } }