public async Task <bool> LoginWithToken() { try { if (App.UserToken == null && App.User == null) { var tokenVal = await SecureStorage.GetAsync("userToken"); if (tokenVal != null) { var user = await authProvider.GetUserAsync(tokenVal); App.UserToken = tokenVal; App.User = user; return(true); } else { return(false); } } else { return(true); } } catch (Exception) { return(false); } }
public async Task <Response> Login(Model.User user) { try { var authLink = await authProvider.SignInWithEmailAndPasswordAsync(user.EmailID, user.Password); firebaseUser = await authProvider.GetUserAsync(authLink.FirebaseToken); client = new FirebaseClient(Config.FirebaseWebApp, new FirebaseOptions { AuthTokenAsyncFactory = () => Task.FromResult <string>(authLink.FirebaseToken) } ); storageClient = new FirebaseStorage(Config.FirebaseStorageApp, new FirebaseStorageOptions { AuthTokenAsyncFactory = () => Task.FromResult <string>(authLink.FirebaseToken) } ); return(new Response { Success = true, Code = (firebaseUser.IsEmailVerified) ? Code.Default : Code.EmailNotVerified }); } catch (Exception ex) { return(new Response { Success = false }); } }
public string WhoFirebase() { // return "sdsds dsds"; var token = "AIzaSyBSD5vZpqL2Q0hV-CDwX6T7oYKTbEernjQ"; // specify your app’s client key when creating the auth provider var ap = new FirebaseAuthProvider(new FirebaseConfig(token)); // var result3=ap.CreateUserWithEmailAndPasswordAsync("xxx", "ccc").Result; // var result3 = ap.CreateUserWithEmailAndPasswordAsync("xxx", "ccc").Result; // FirebaseAuthLink rr = ap.SignInWithEmailAndPasswordAsync("", "").Result; // sign in with OAuth. You can also sign in anonymously var auth = ap.SignInWithEmailAndPasswordAsync("*****@*****.**", "0549411222").Result; var ddd = auth.FirebaseToken; try { var ddddd = ap.GetUserAsync(ddd).Result; return(ddddd.FirstName + " " + ddddd.LastName); } catch (Exception w3w) { throw w3w; } }
public async Task <bool> SignInUser(string email, string password) { try { _authLink = await authProvider.SignInWithEmailAndPasswordAsync(email, password); String token = _authLink.FirebaseToken; SaveFirebaseAuth(_authLink); // token = Settings.FirebaseAuthJson; Firebase.Auth.User user = await authProvider.GetUserAsync(token); if (user.IsEmailVerified == false) { ResendEmailVerification(_authLink.FirebaseToken); String massage = String.Format("الحساب غير مفعل سوف نعيد ارسال رابط التفعيل الا الايميل ", email); await App.Current.MainPage.DisplayAlert("تأكيد", massage, "موافق"); } return(user.IsEmailVerified); } catch (FirebaseAuthException ee) { switch (ee.Reason) { case AuthErrorReason.WrongPassword: await App.Current.MainPage.DisplayAlert("خطأ", " كلمة السر غير صحيحة", "موافق"); break; case AuthErrorReason.UnknownEmailAddress: await App.Current.MainPage.DisplayAlert("خطأ", " الايميل غير مستخدم", "موافق"); break; } return(false); } catch (System.Exception e) { return(false); throw e; } }
static void Main(string[] args) { eDataType dd = (eDataType)Enum.Parse(typeof(eDataType), "open"); /* * */ var token = "AIzaSyBSD5vZpqL2Q0hV-CDwX6T7oYKTbEernjQ"; // specify your app’s client key when creating the auth provider var ap = new FirebaseAuthProvider(new FirebaseConfig(token)); // var result3=ap.CreateUserWithEmailAndPasswordAsync("xxx", "ccc").Result; // var result3 = ap.CreateUserWithEmailAndPasswordAsync("xxx", "ccc").Result; // FirebaseAuthLink rr = ap.SignInWithEmailAndPasswordAsync("", "").Result; // sign in with OAuth. You can also sign in anonymously var auth = ap.SignInWithEmailAndPasswordAsync("*****@*****.**", "x").Result; var ddd = auth.FirebaseToken; var ddddd = ap.GetUserAsync(ddd).Result; Console.WriteLine("{0},{1}", ddddd.Email, ddddd.LastName); Console.ReadLine(); var firebase = new FirebaseClient( "https://fir-tocrm.firebaseio.com", new FirebaseOptions { AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken) }); var dinos = firebase .Child("posts") .OnceAsync <PostDetail>().Result; foreach (var dino in dinos) { Console.WriteLine($"{dino.Key} is {dino.Object.author }m high."); } }
async void LoginButton_Clicked(System.Object sender, System.EventArgs e) { var authProvider = new FirebaseAuthProvider(new FirebaseConfig("AIzaSyAg4riVkvSMtWwKZ6_UssK28-2K6xOndrg")); try { var auth = await authProvider.SignInWithEmailAndPasswordAsync(UserLoginEmail.Text, UserLoginPassword.Text); var user = await authProvider.GetUserAsync(auth.FirebaseToken); if (!user.IsEmailVerified) { await App.Current.MainPage.DisplayAlert("Mail", "Potvrdite mail adresu kako bi nastavili koristiti aplikaciju.", "Ok"); } else { var users = await UserDataStore.GetItemsAsync(false); var firebaseUser = users.Where(u => u.Username == user.DisplayName).FirstOrDefault(); if (firebaseUser != null) { var serializedUser = JsonConvert.SerializeObject(firebaseUser); Preferences.Set("FirebaseUser", serializedUser); await App.Current.MainPage.DisplayAlert("Successfull", $"Pozdrav {user.DisplayName}, uspješno ste izvršili prijavu!", "OK"); await Navigation.PushAsync(new MainPage()); } else { await App.Current.MainPage.DisplayAlert("Pogreška", $"Korisnik ne postoji.", "OK"); } } } catch (Exception ex) { await App.Current.MainPage.DisplayAlert("Upozorenje", "Neispravni podatci za prijavu.", "OK"); } }
public async Task <User> GetUserAsync(string firebaseToken) { return(await _firebaseAuthProvider.GetUserAsync(firebaseToken)); }
internal Task <User> GetUpdatedUserAsync() => _authProvider.GetUserAsync(AuthLink);
async void RegistrationButton_Clicked(System.Object sender, System.EventArgs e) { if ( String.IsNullOrEmpty(newuser_username.Text) || String.IsNullOrEmpty(newuser_email.Text) || String.IsNullOrEmpty(newuser_firstname.Text) || String.IsNullOrEmpty(newuser_lastname.Text) || String.IsNullOrEmpty(newuser_password.Text) || String.IsNullOrEmpty(newuser_phonenumber.Text) ) { await App.Current.MainPage.DisplayAlert("Info", "Za registraciju potrebno je ispuniti sva polja", "OK"); } else { try { bool isSuccessful = false; FirebaseUser firebaseUser = new FirebaseUser(); User user = new User(); using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Dohvaćam podatke..")) { var users = await UserDataStore.GetItemsAsync(false); var username_alreadyexists = users.Where(u => u.Username == newuser_username.Text).FirstOrDefault(); var email_alreadyexists = users.Where(u => u.Email == newuser_email.Text).FirstOrDefault(); if (username_alreadyexists != null) { throw new FirebaseAuthException(null, null, null, null, reason: AuthErrorReason.UserNotFound); } if (email_alreadyexists != null) { throw new FirebaseAuthException(null, null, null, null, reason: AuthErrorReason.EmailExists); } var authProvider = new FirebaseAuthProvider(new FirebaseConfig("AIzaSyAg4riVkvSMtWwKZ6_UssK28-2K6xOndrg")); var auth = await authProvider.CreateUserWithEmailAndPasswordAsync(newuser_email.Text, newuser_password.Text, newuser_username.Text, true); user = await authProvider.GetUserAsync(auth.FirebaseToken); } if (!user.IsEmailVerified) { var allFbUsers = await UserDataStore.GetItemsAsync(false); var fbUser = allFbUsers.Where(f => f.Email == user.Email).FirstOrDefault(); firebaseUser = fbUser; if (firebaseUser != null) { isSuccessful = true; } else { firebaseUser = new FirebaseUser { Email = newuser_email.Text, Username = newuser_username.Text, Year = DateTime.Now.Year.ToString(), FirstName = newuser_firstname.Text, LastName = newuser_lastname.Text, PicturePath = "https://png.pngtree.com/png-vector/20190710/ourmid/pngtree-user-vector-avatar-png-image_1541962.jpg", PhoneNumber = newuser_phonenumber.Text }; isSuccessful = await UserDataStore.AddItemAsync(firebaseUser); } if (isSuccessful) { await App.Current.MainPage.DisplayAlert("Uspješna registracija", "Potvrdite mail adresu kako bi nastavili koristiti aplikaciju.", "Ok"); App.Current.MainPage = new NavigationPage(new UserPage()); } else { await App.Current.MainPage.DisplayAlert("Greška", "Pokušajte ponovno ili se obratite korisničkoj podršci", "Ok"); } } } catch (FirebaseAuthException ex) { if (ex.Reason.Equals(Firebase.Auth.AuthErrorReason.EmailExists)) { await App.Current.MainPage.DisplayAlert("Upozorenje", "Račun sa ovom mail adresom već postoji. Pokušajte ponovno ili se prijavite sa google-om.", "OK"); } else if (ex.Reason.Equals(Firebase.Auth.AuthErrorReason.InvalidEmailAddress)) { await App.Current.MainPage.DisplayAlert("Upozorenje", "Email adresa nije valjana. Pokušajte ponovno ili upišite neku drugu email adresu.", "OK"); } else if (ex.Reason.Equals(Firebase.Auth.AuthErrorReason.WeakPassword)) { await App.Current.MainPage.DisplayAlert("Upozorenje", "Lozinka mora biti dugačka barem 7 znakova, mora se sastojati od kojih barem jedan mora biti znak i barem jedan broj.", "OK"); } else if (ex.Reason.Equals(Firebase.Auth.AuthErrorReason.UserNotFound)) { await App.Current.MainPage.DisplayAlert("Upozorenje", "Već postoji osoba s tim korisničkim imenom!", "OK"); } else if (ex.Reason.Equals(Firebase.Auth.AuthErrorReason.InvalidEmailAddress)) { await App.Current.MainPage.DisplayAlert("Upozorenje", "Neispravna mail adresa!", "OK"); } else if (ex.Reason.Equals(Firebase.Auth.AuthErrorReason.WrongPassword)) { await App.Current.MainPage.DisplayAlert("Upozorenje", "Neispravna lozinka!", "OK"); } else { await App.Current.MainPage.DisplayAlert("Alert", ex.Message, "OK"); } } } }