public void Login_Anonymous() { FirebaseAuth.DefaultInstance.SignInAnonymouslyAsync().ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { print("User is LOGGED IN"); } })); }
public void RegisterUser() { if (emailInput.text.Equals("") && passwordInput.text.Equals("")) { print("Please enter an email and password to register"); return; } FirebaseAuth.DefaultInstance.CreateUserWithEmailAndPasswordAsync(emailInput.text, passwordInput.text) .ContinueWith(( task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { print("Registration COMPLETE"); } })); }
public void Login() { FirebaseAuth.DefaultInstance.SignInWithEmailAndPasswordAsync(emailInput.text, passwordInput.text).ContinueWith( (task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { print("User is LOGGED IN"); } })); }
public void Login_Anonymous() { FirebaseAuth.DefaultInstance.SignInAnonymouslyAsync().ContinueWith(task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { entered = true; //StartCoroutine(StartApp()); StartApp(); //GoToApp(); Debug.Log(entered); } //SceneManager.LoadScene(0); }, TaskScheduler.FromCurrentSynchronizationContext()); }
public void Login() { outputText.text = "Login processing"; auth.SignInWithEmailAndPasswordAsync( emailInput.text, passwordInput.text) .ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } user = task.Result; print("Login successful " + user.Email); })); loginButtonText.text = "logout"; DisplayOutput("Login successful"); DisplayOutput("Hi " + user.Email); }
public void RegisterUser() { if (emailField.text.Equals("") && passwordField.text.Equals("")) { print("Enter an email and a password to register"); return; } FirebaseAuth.DefaultInstance.CreateUserWithEmailAndPasswordAsync(emailField.text, passwordField.text). ContinueWith(task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { //StartApp(); return; } }); }
// Log the result of the specified task, returning true if the task // completed successfully, false otherwise. public bool LogTaskCompletion(Task task, string operation) { bool complete = false; if (task.IsCanceled) { DebugLog(operation + " canceled."); } else if (task.IsFaulted) { DebugLog(operation + " encounted an error."); foreach (Exception exception in task.Exception.Flatten().InnerExceptions) { string authErrorCode = ""; Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException; if (firebaseEx != null) { authErrorCode = String.Format("AuthError.{0}: ", ((Firebase.Auth.AuthError)firebaseEx.ErrorCode).ToString()); } DebugLog(authErrorCode + exception.ToString()); } } else if (task.IsCompleted) { DebugLog(operation + " completed"); complete = true; } return(complete); }
public void GetPhotoPath() { //lastStatus = statusText.GetComponent<Text>().text; //photoRawImage.texture = dogTexture; FirebaseDatabase.DefaultInstance.GetReferenceFromUrl(DATA_URL).Child(spreadsheetID).Child(photoUID.text).GetValueAsync() .ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { DataSnapshot snapshot = task.Result; //task.Result; string t = snapshot.GetRawJsonValue(); PhotoData extractedData = JsonUtility.FromJson <PhotoData>(t); print("Filename is: " + extractedData.Filename); lastStatus = "Filename is: " + extractedData.Filename; newFilename = extractedData.Filename; } })); }
public void Login() { //Console(""); FirebaseAuth.DefaultInstance.SignInWithEmailAndPasswordAsync(LoginemailInput.text, LoginpasswordInput.text) .ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { print("Login COMPLETE"); GetUid(); Load(); } })); }
public void LoginAsGuest() { FirebaseAuth.DefaultInstance.SignInAnonymouslyAsync() .ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { print("Guest login successful"); RegisterSuccessful(); return; } })); }
// Log the result of the specified task, returning true if the task // completed successfully, false otherwise. protected bool LogTaskCompletion(Task task, string operation) { if (task.IsCanceled) { Debug.Log(operation + " canceled."); } else if (task.IsFaulted) { Debug.Log(operation + " encounted an error."); foreach (Exception exception in task.Exception.Flatten().InnerExceptions) { string authErrorCode = ""; Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException; if (firebaseEx != null) { authErrorCode = String.Format("AuthError.{0}: ", ((Firebase.Auth.AuthError)firebaseEx.ErrorCode).ToString()); } Debug.Log(authErrorCode + exception.ToString()); //error_text.text = "Error" + exception.ToString(); error_text.text = "ERROR: " + firebase_helper.get_firebase_exception(task.Exception as AggregateException); error_text.enabled = true; } } else if (task.IsCompleted) { Debug.Log(operation + " completed"); } return(task.IsCompleted);// complete; }
public void clickOnUpdateAvatar() { String nickname = this.nickname.text; FirebaseUser currentUser = UserLogged.getLoggedUser(); if (!string.IsNullOrEmpty(nickname)) { if (currentUser != null) { Firebase.Auth.UserProfile profile = new Firebase.Auth.UserProfile { DisplayName = nickname, }; currentUser.UpdateUserProfileAsync(profile).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("UpdateUserProfileAsync was canceled."); return; } if (task.IsFaulted) { infoMessage.faceColor = new Color32(255, 0, 0, 255); AggregateException ex = task.Exception as AggregateException; if (ex != null) { Firebase.FirebaseException fbEx = null; foreach (Exception e in ex.InnerExceptions) { fbEx = e as Firebase.FirebaseException; if (fbEx != null) { break; } } if (fbEx != null) { infoMessage.text = fbEx.Message; } } return; } infoMessage.faceColor = new Color32(0, 255, 0, 255); infoMessage.text = "User profile updated successfuly!"; GameObject gameObj = GameObject.Find("User"); DontDestroyOnLoad(gameObj); SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); }); } } else { infoMessage.faceColor = new Color32(255, 0, 0, 255); infoMessage.text = "Please enter a nickname!"; } }
public void Register() { isNewUser = true; Debug.Log("enter register method"); username = GameObject.Find("UsernameInput").GetComponent <InputField>(); password = GameObject.Find("PasswordInput").GetComponent <InputField>(); repassword = GameObject.Find("RePassInput").GetComponent <InputField>(); if (password.text != repassword.text) { LoginRegisterFeedback.GetComponent <TextMeshProUGUI>().text = "passwords do not match"; LoginRegisterFeedback.SetActive(true); return; } auth.CreateUserWithEmailAndPasswordAsync(username.text, password.text).ContinueWith(task => { if (task.IsCanceled) { Debug.Log("CreateUserWithEmailAndPasswordAsync was canceled."); lastMessage = currentMessage; // currently only displays 1 exception // might need to append to string instead of replacing foreach (System.Exception exception in task.Exception.Flatten().InnerExceptions) { Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException; if (firebaseEx != null) { currentMessage = firebaseEx.Message; AuthStateChanged(this, null); } } return; } if (task.IsFaulted) { Debug.Log("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception); lastMessage = currentMessage; // currently only displays 1 exception // might need to append to string instead of replacing foreach (System.Exception exception in task.Exception.Flatten().InnerExceptions) { Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException; if (firebaseEx != null) { currentMessage = firebaseEx.Message; AuthStateChanged(this, null); } } return; } // Firebase user has been created. Firebase.Auth.FirebaseUser newUser = null; newUser = task.Result; Debug.LogFormat("Firebase user created successfully: {0} ({1})", newUser.DisplayName, newUser.UserId); }); }
public void HandleAuthError() { List <string> myList; FirebaseDatabase.DefaultInstance.GetReferenceFromUrl(PlayerDataUrl).GetValueAsync().ContinueWith(task => { if (task.IsCanceled) { Firebase.FirebaseException exep = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage(exep.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException exep = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage(exep.ErrorCode); return; } // DataSnapshot is an object that stores all of the player's data DataSnapshot SnapshotData = task.Result; string PlayerData = SnapshotData.GetRawJsonValue(); print(PlayerData); myList = new List <string>(); foreach (var child in SnapshotData.Children) { string childData = child.GetRawJsonValue(); Player eachField = JsonUtility.FromJson <Player>(childData); if (eachField.Email != "") { myList.Add(eachField.Email); } foreach (string s in myList) { AuthErrorLocal = false; Console.WriteLine(s); if (s == eachField.Email) { AuthErrorLocal = true; // break; } else { AuthErrorLocal = false; } } } }); }
public void LoadData() { DateTime startTime = DateTime.Now; lastStatus = "Starting large database read..."; print("Starting database read..."); FirebaseDatabase.DefaultInstance.GetReferenceFromUrl(DATA_URL).Child(spreadsheetID).GetValueAsync() .ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { DataSnapshot snapshot = task.Result; //task.Result; string photoData = snapshot.GetRawJsonValue(); //print("photoData = " + photoData); int rowCount = 0; foreach (var child in snapshot.Children) { string t = child.GetRawJsonValue(); rowCount++; PhotoData extractedData = JsonUtility.FromJson <PhotoData>(t); //print("row " + rowCount + " t: " + t); //print("photoUID: " + extractedData.Photo_uid + ", size: " + extractedData.Size + ", location: " + extractedData.Location); //print("extractedData = " + extractedData); } lastStatus = "Read " + rowCount + " rows from database."; print("Read " + rowCount + " rows from database."); TimeElapsed(startTime); } })); }
// Create a user with the email and password. public Task CreateUserWithEmailAsync(string email, string password, string displayname) { Debug.Log(String.Format("Attempting to create user {0}...", email)); DisableUI(); // This passes the current displayName through to HandleCreateUserAsync // so that it can be passed to UpdateUserProfile(). displayName will be // reset by AuthStateChanged() when the new user is created and signed in. string newDisplayName = displayName; return(auth.CreateUserWithEmailAndPasswordAsync(email, password) .ContinueWithOnMainThread((task) => { EnableUI(); // if (task.IsCanceled) { Debug.Log("register canceled."); } else if (task.IsFaulted) { Debug.Log("register is failed"); foreach (Exception exception in task.Exception.Flatten().InnerExceptions) { string authErrorCode = ""; Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException; if (firebaseEx != null) { authErrorCode = String.Format("AuthError.{0}: ", ((Firebase.Auth.AuthError)firebaseEx.ErrorCode).ToString()); } Debug.Log("Here Print" + exception.ToString()); showToast(exception.ToString(), 3); } } else if (task.IsCompleted) { Debug.Log("succeesful sign up"); user_name = displayname; win = 0; loss = 0; UpdateUserProfileAsync(displayname + "&0&0"); //load user panel panellaoder.LoadUserPanelScene(); } return task; }).Unwrap()); }
public static string GetErrorMessage(Exception exception) { Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException; AggregateException ex = exception as AggregateException; if (ex != null) { Firebase.FirebaseException inner = ex.InnerExceptions[0] as Firebase.FirebaseException; return(GetCodeErrorMessage((AuthError)inner.ErrorCode)); } return(exception.Message.ToString()); }
public void Login() { // retrieve username and password username = GameObject.Find("UsernameInput").GetComponent <InputField>(); password = GameObject.Find("PasswordInput").GetComponent <InputField>(); // attempt to login auth.SignInWithEmailAndPasswordAsync(username.text, password.text).ContinueWith(task => { if (task.IsCanceled) { Debug.Log("SignInWithEmailAndPasswordAsync was canceled."); lastMessage = currentMessage; // currently only displays 1 exception // might need to append to string instead of replacing foreach (System.Exception exception in task.Exception.Flatten().InnerExceptions) { Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException; if (firebaseEx != null) { currentMessage = firebaseEx.Message; AuthStateChanged(this, null); } } return; } if (task.IsFaulted) { Debug.Log("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception.ToString()); lastMessage = currentMessage; // currently only displays 1 exception // might need to append to string instead of replacing foreach (System.Exception exception in task.Exception.Flatten().InnerExceptions) { Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException; if (firebaseEx != null) { currentMessage = firebaseEx.Message; AuthStateChanged(this, null); } } return; } // successful login AuthStateChanged(this, null); user = task.Result; Debug.LogFormat("User signed in successfully."); }); }
public Task LoadData_ReturnTask(string level) { return(databaseReference.Child(usrEmail + "_" + level).GetValueAsync().ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; AuthError msg = (AuthError)e.ErrorCode; loadError = msg.ToString(); print("Error: " + loadError); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; AuthError msg = (AuthError)e.ErrorCode; loadError = msg.ToString(); print("Error: " + loadError); return; } if (task.IsCompleted) { DataSnapshot snapshot = task.Result; string playerData = snapshot.GetRawJsonValue(); foreach (var child in snapshot.Children) { string t = child.GetRawJsonValue(); GameStatistics extractedData = JsonUtility.FromJson <GameStatistics>(t); AttemptsList.Add(extractedData.gameAttempts); DurationList.Add(extractedData.gameDuration); LevelPassedList.Add(extractedData.levelPassed); } print("Data loaded successfully!"); loadSuccessful = true; } }))); }
public Task LoadDataManager(string activityName, string activityLevel) { return(databaseReference.Child(usrEmail + "_" + activityName + "_" + activityLevel).GetValueAsync().ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; AuthError msg = (AuthError)e.ErrorCode; loadError = msg.ToString(); print("Error: " + loadError); } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; AuthError msg = (AuthError)e.ErrorCode; loadError = msg.ToString(); print("Error: " + loadError); } if (task.IsCompleted) { DataSnapshot snapshot = task.Result; string playerData = snapshot.GetRawJsonValue(); foreach (var child in snapshot.Children) { string t = child.GetRawJsonValue(); GameStatistics extractedData = JsonUtility.FromJson <GameStatistics>(t); LevelPassedList.Add(extractedData.levelPassed); } //If the level is not passed, hide next levels (buttons). int times_passed = countOccurences(LevelPassedList, "yes"); if (times_passed == 0) { levelPassedFlag = false; } else { levelPassedFlag = true; } } }))); }
void Awake() { Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance; auth.SignInAnonymouslyAsync().ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SignInAnonymouslyAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SignInAnonymouslyAsync encountered an error: " + task.Exception); AggregateException ex = task.Exception as AggregateException; if (ex != null) { Firebase.FirebaseException fbEx = null; foreach (Exception e in ex.InnerExceptions) { fbEx = e as Firebase.FirebaseException; if (fbEx != null) { break; } } if (fbEx != null) { Debug.LogError("Encountered a FirebaseException:" + fbEx.Message); } } //Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug; return; } user = task.Result; Passport.Id = user.UserId; OpenedPassport.Id = user.UserId; answerOne.Id = user.UserId; answerTwo.Id = user.UserId; answerThree.Id = user.UserId; Debug.LogFormat("User signed in successfully: {0} ({1})", user.DisplayName, user.UserId); }); }
public void RegisterUser() { if (RegEmail.text.Equals("") && password.text.Equals("")) { print("Enter Email/Password"); return; } if (password.text != reEnterPass.text) { print("Passwords don't match"); return; } FirebaseAuth.DefaultInstance.CreateUserWithEmailAndPasswordAsync(RegEmail.text, password.text).ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { print("Registration COMPLETE"); RegistrationComplete = true; } })); UserName = userName.text; EmailID = RegEmail.text; Name = nameField.text; Coins = 50; PostToDatabase(); GoToLoginCanvas(); }
// Loads player's data public void LoadData() { FirebaseDatabase.DefaultInstance.GetReferenceFromUrl(PlayerDataUrl).GetValueAsync().ContinueWith(task => { if (task.IsCanceled) { Firebase.FirebaseException exep = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage(exep.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException exep = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage(exep.ErrorCode); return; } if (task.IsCompleted) { // DataSnapshot is an object that stores all of the player's data DataSnapshot SnapshotData = task.Result; string PlayerData = SnapshotData.GetRawJsonValue(); print(PlayerData); foreach (var child in SnapshotData.Children) { string childData = child.GetRawJsonValue(); Player eachField = JsonUtility.FromJson <Player>(childData); //Ready to retrieve any of it's childs easily //print("The Player's id is: " + eachField.Id); //print("The Player's name is : " + eachField.Name); //print("The Player's email is: " + eachField.Email); //print("The Player's username is: " + eachField.Username); //print("The Player's password is: " + eachField.Password); } } }); }
// Called when a sign-in without fetching profile data completes. void HandleSignInWithUser(Task <Firebase.Auth.FirebaseUser> task) { if (task.IsCanceled) { Debug.Log("sign in canceled."); } else if (task.IsFaulted) { Debug.Log("SignIn is failed"); foreach (Exception exception in task.Exception.Flatten().InnerExceptions) { string authErrorCode = ""; Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException; if (firebaseEx != null) { authErrorCode = String.Format("AuthError.{0}: ", ((Firebase.Auth.AuthError)firebaseEx.ErrorCode).ToString()); } Debug.Log("Here Print" + exception.ToString()); showToast(exception.ToString(), 3); } } else if (task.IsCompleted) { Debug.Log("succeesful sign in"); handel_(auth.CurrentUser.DisplayName); //load user panel panellaoder.LoadUserPanelScene(); } /* * EnableUI(); * if (LogTaskCompletion(task, "Sign-in")) * { * Debug.Log(String.Format("{0} signed in", task.Result.DisplayName)); * } * */ }
public void SaveData() { if (photoUID.text.Equals("")) { print("NO DATA"); return; } // example below will update location field databaseReference.Child(spreadsheetID).Child(photoUID.text).Child("Comments"). SetValueAsync(location.text).ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { print("Success writing!"); lastStatus = "Success writing " + photoUID.text; } })); }
public static string get_firebase_exception(AggregateException ex) { //AggregateException ex = task.Exception as AggregateException; if (ex != null) { Firebase.FirebaseException fbEx = null; foreach (Exception e in ex.InnerExceptions) { fbEx = e as Firebase.FirebaseException; if (fbEx != null) { break; } } if (fbEx != null) { Debug.LogError("Encountered a FirebaseException:" + fbEx.Message); return(fbEx.Message); } } return(""); }
public void RegisterNewUser() { if (emailInput.text.Equals("") || passwordInput.text.Equals("")) { DisplayOutput("Please input your email and password"); return; } else { FirebaseAuth.DefaultInstance.CreateUserWithEmailAndPasswordAsync( emailInput.text, passwordInput.text) .ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { Firebase.Auth.FirebaseUser newUser = task.Result; Debug.LogFormat("Firebase user created successfully: {0} ({1})", newUser.Email, newUser.UserId); } })); DisplayOutput("Registered"); } }
public void Register() { if (aluno.isOn) { role = "aluno"; } else { role = "professor"; } //Console(""); FirebaseAuth.DefaultInstance.CreateUserWithEmailAndPasswordAsync(RegisteremailInput.text, RegisterpasswordInput.text) .ContinueWith((task => { if (task.IsCanceled) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsFaulted) { Firebase.FirebaseException e = task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException; GetErrorMessage((AuthError)e.ErrorCode); return; } if (task.IsCompleted) { print("Registration COMPLETE"); uid = task.Result.UserId; SaveUser(usernameInput.text, role, uid); Load(); } })); }
protected virtual void InitializeFirebase() { VariablesRealTime.auth = Firebase.Auth.FirebaseAuth.DefaultInstance; VariablesRealTime.auth.SignInWithEmailAndPasswordAsync(inputFieldEmail.text, inputFieldPassword.text).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SignInWithEmailAndPasswordAsync was canceled."); AggregateException ex = task.Exception as AggregateException; if (ex != null) { panelLoading.SetActive(false); ok = false; Firebase.FirebaseException fbEx = null; foreach (Exception e in ex.InnerExceptions) { fbEx = e as Firebase.FirebaseException; if (fbEx != null) { break; } } if (fbEx != null) { textWarning.color = Color.red; textWarning.text = fbEx.Message; } } return; } if (task.IsFaulted) { panelLoading.SetActive(false); ok = false; Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception.Message); AggregateException ex = task.Exception as AggregateException; if (ex != null) { Firebase.FirebaseException fbEx = null; foreach (Exception e in ex.InnerExceptions) { fbEx = e as Firebase.FirebaseException; if (fbEx != null) { break; } } if (fbEx != null) { textWarning.color = Color.red; textWarning.text = fbEx.Message; } } return; } Firebase.Auth.FirebaseUser newUser = task.Result; Debug.LogFormat("User signed in successfully: {0} ({1})", newUser.DisplayName, newUser.UserId); VariablesRealTime.eMail = inputFieldEmail.text; VariablesRealTime.password = inputFieldPassword.text; VariablesRealTime.newUser = task.Result; Debug.Log(VariablesRealTime.newUser); Screen.orientation = ScreenOrientation.Landscape; SceneManager.LoadScene("Main"); /*menuCanvas.SetActive(true); * selfCanvas.SetActive(false);*/ }); }
public void SignUp() { if (TestEmail.IsEmail(inputFieldEmail.text) && inputFieldEmail.text != "" && inputFieldPassword.text != "" && inputFieldEmail.text != " " && inputFieldEmail.text != " " && inputFieldNickName.text != "" && inputFieldNickName.text != " " && inputFieldPasswordAgain.text != "" && inputFieldPasswordAgain.text != " " && inputFieldPassword.text == inputFieldPasswordAgain.text) { if (Application.internetReachability == NetworkReachability.NotReachable) { textWarning.text = "Error. Check internet connection!"; } else { panelLoading.SetActive(true); ok = true; VariablesRealTime.auth.CreateUserWithEmailAndPasswordAsync(inputFieldEmail.text, inputFieldPassword.text).ContinueWith(task => { if (task.IsCanceled) { panelLoading.SetActive(false); ok = false; Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled."); AggregateException ex = task.Exception as AggregateException; if (ex != null) { Firebase.FirebaseException fbEx = null; foreach (Exception e in ex.InnerExceptions) { fbEx = e as Firebase.FirebaseException; if (fbEx != null) { break; } } if (fbEx != null) { textWarning.color = Color.red; textWarning.text = fbEx.Message; } } return; } if (task.IsFaulted) { panelLoading.SetActive(false); ok = false; Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception); AggregateException ex = task.Exception as AggregateException; if (ex != null) { Firebase.FirebaseException fbEx = null; foreach (Exception e in ex.InnerExceptions) { fbEx = e as Firebase.FirebaseException; if (fbEx != null) { break; } } if (fbEx != null) { textWarning.color = Color.red; textWarning.text = fbEx.Message; } } return; } if (task.IsCompleted) { textWarning.color = Color.green; textWarning.text = "Count Created"; FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://snowballs-98497.firebaseio.com/"); DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference; User user = new User ( inputFieldNickName.text, inputFieldEmail.text, inputFieldPassword.text, task.Result.UserId, 1, 0, 0, 100f ); VariablesRealTime.eMail = inputFieldEmail.text; VariablesRealTime.password = inputFieldPassword.text; VariablesRealTime.newUser = task.Result; string json = JsonUtility.ToJson(user); reference.Child("users").Child(task.Result.UserId).SetRawJsonValueAsync(json).ContinueWith((task3) => { if (task3.IsFaulted) { textWarning.text = task3.Exception.Message; panelLoading.SetActive(false); ok = false; return; } if (task3.IsCompleted) { SceneManager.LoadScene("Main"); } }); } }); } } else { textWarning.text = "Please Check Your Email Or Password Or Your User Name"; } { if (inputFieldPasswordAgain.text != inputFieldPassword.text) { textWarning.color = Color.red; textWarning.text = "Your Password Does Not Match"; } } }