void SignUpButtonClicked() { FirebaseAuth.DefaultInstance.CreateUserWithEmailAndPasswordAsync(emailInput.text, passwordInput.text).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception); return; } // Firebase user has been created. Firebase.Auth.FirebaseUser newUser = task.Result; Debug.LogFormat("Firebase user created successfully: {0} ({1})", newUser.DisplayName, newUser.UserId); newUser.SendEmailVerificationAsync().ContinueWith(t => { Debug.LogFormat("SendEmailVerificationAsync Success"); WriteNewUserToDataBase(newUser.UserId, newUser.Email); }); }); SceneManager.LoadScene(0); }
// Email+pass+name // ref: https://firebase.google.com/docs/auth/unity/password-auth public static void AuthCreateUser(string email, string password) { if (!setupReady) { return; } if (authPhases == -1) { return; } lastError = ""; authPhases = -1; auth = Firebase.Auth.FirebaseAuth.DefaultInstance; auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => { if (task.IsCanceled) { lastError = task.Exception.ToString(); authPhases = 0; return; } if (task.IsFaulted) { lastError = task.Exception.InnerExceptions[0].InnerException.Message; authPhases = 0; //foreach (Exception ie in e.InnerExceptions) // Console.WriteLine("{0}: {1}", ie.GetType().Name, // ie.Message); return; } Firebase.Auth.FirebaseUser user = auth.CurrentUser; if (user != null) { user.SendEmailVerificationAsync().ContinueWith(task2 => { if (task2.IsCanceled) { lastError = task2.Exception.ToString(); authPhases = 0; return; } if (task2.IsFaulted) { lastError = task2.Exception.InnerExceptions[0].InnerException.Message; authPhases = 0; return; } authPhases = 1; FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventSignUp); AuthUpdateUser(); // Debug.LogFormat("User signed in successfully: {0} ({1})", newUser.DisplayName, newUser.UserId); }); } }); }
private void LoginwithEmail(string email, string password) { Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance; auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(task => { if (task.IsCanceled) { PopupMsg.text = "Check your Email or Password"; PopupPanel.SetActive(true); Debug.LogError("SignInWithEmailAndPasswordAsync was canceled."); return; } if (task.IsFaulted) { PopupMsg.text = "Check your Email or Password"; PopupPanel.SetActive(true); Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception); return; } Firebase.Auth.FirebaseUser newUser = task.Result; UserName = newUser.DisplayName; Debug.LogFormat("User signed in successfully: {0} ({1})", newUser.DisplayName, newUser.UserId); }); Firebase.Auth.FirebaseUser user = auth.CurrentUser; if (user != null) { user.SendEmailVerificationAsync().ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SendEmailVerificationAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SendEmailVerificationAsync encountered an error: " + task.Exception); return; } Debug.Log("Email sent successfully."); }); string myname = user.DisplayName; string myemail = user.Email; System.Uri myphoto_url = user.PhotoUrl; // The user's Id, unique to the Firebase project. // Do NOT use this value to authenticate with your backend server, if you // have one; use User.TokenAsync() instead. string uid = user.UserId; } }
void ConfirmarEmail() { Firebase.Auth.FirebaseUser user = auth.CurrentUser; if (user != null) { user.SendEmailVerificationAsync().ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SendEmailVerificationAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SendEmailVerificationAsync encountered an error: " + task.Exception); return; } Debug.Log("Email sent successfully."); }); } }
public void RegisterNewAccount() { auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled"); return; } if (task.IsFaulted) { Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception); return; } Firebase.Auth.FirebaseUser newUser = task.Result; Debug.LogFormat("Firebase user created successfully: {0} ({1})", newUser.DisplayName, newUser.UserId); newUser.SendEmailVerificationAsync().ContinueWith(t => { Debug.Log("Verification Email Sent"); }); }); }
void LoginButtonClicked() { if (CanLogin == true) { FirebaseAuth.DefaultInstance.SignInWithEmailAndPasswordAsync(EmailAddress.text, Password.text).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SignInWithEmailAndPasswordAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception); return; } Firebase.Auth.FirebaseUser newUser = task.Result; if (newUser.IsEmailVerified == false) { Debug.Log("Please Verify Email Address"); newUser.SendEmailVerificationAsync().ContinueWith(t => { Debug.LogFormat("SendEmailVerificationAsync Success"); newUser = null; }); return; } if (newUser.IsEmailVerified) { Debug.LogFormat("User signed in successfully: {0} ({1})", newUser.DisplayName, newUser.UserId); user = FirebaseAuth.DefaultInstance.CurrentUser; _Bridge.loadData(newUser.UserId); } }); } }
private void sendEmailVerification(Firebase.Auth.FirebaseUser user, string name) { user.SendEmailVerificationAsync().ContinueWithOnMainThread(task => { if (task.IsCanceled) { Debug.LogError("SendEmailVerification cancelled."); popUp.SendMessage("activatePopUp", "Error! " + task.Exception); return; } if (task.IsFaulted) { Debug.LogError("SendEmailVerification error: " + task.Exception); popUp.SendMessage("activatePopUp", "Error! " + task.Exception); return; } Debug.Log("SendEmailVerification to: " + user.Email); popUp.SendMessage("setSceneChange", (int)0); popUp.SendMessage("setOkButton", "ChangeScene"); popUp.SendMessage("activatePopUp", "Register Success! Check Email to Verify"); addToUserDB(registerThisUser); }); }
Task HandleCreateUserAsync(Task <Firebase.Auth.FirebaseUser> authTask, string newDisplayName = null) { EnableUI(); if (LogTaskCompletion(authTask, "User Creation")) { if (auth.CurrentUser != null) { DebugLog(String.Format("User Info: {0} {1}", auth.CurrentUser.Email, auth.CurrentUser.ProviderId)); Firebase.Auth.FirebaseUser user = auth.CurrentUser; if (user != null) { user.SendEmailVerificationAsync().ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SendEmailVerificationAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SendEmailVerificationAsync encountered an error: " + task.Exception); return; } Debug.Log("Email sent successfully."); }); } return(UpdateUserProfileAsync(newDisplayName: newDisplayName)); } } // Nothing to update, so just return a completed Task. return(Task.FromResult(0)); }
public IEnumerator PushUserToFirebase() { firebaseManager.enableLoadingScreen(); Firebase.Auth.FirebaseUser newUser = null; bool done = false; string errorMessage = ""; publicUserData = new PublicUserData(programs, inspirencEmail.text, school.text, memberName.text, "Member", Int32.Parse(grade.text)); privateUserData = new PrivateUserData(personalEmail.text, address.text, parent1name.text, parent1email.text, parent1number.text, parent2name.text, parent2email.text, parent2number.text, phoneNumber.text, getCheckedGender(), Int32.Parse(age.text)); firebaseManager.auth.CreateUserWithEmailAndPasswordAsync(publicUserData.inspirencEmail, passwordInput.text.ToString()).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { errorMessage = errorMessage = (task.Exception.ToString().Substring(task.Exception.ToString().IndexOf("FirebaseException: ") + 19, task.Exception.ToString().Substring(task.Exception.ToString().IndexOf("FirebaseException: ") + 19).IndexOf(".") + 1));; done = true; return; } else if (task.IsCompleted) { newUser = task.Result; done = true; } }); yield return(new WaitUntil(() => done == true)); done = false; if (errorMessage.Equals("The email address is already in use by another account.")) { firebaseManager.setErrorMessage("The email address is already in use by another account."); yield return(new WaitForSeconds(4)); reset(); yield break; } Firebase.Auth.FirebaseUser user = firebaseManager.auth.CurrentUser; if (user != null) { Firebase.Auth.UserProfile profile = new Firebase.Auth.UserProfile { DisplayName = publicUserData.name }; user.UpdateUserProfileAsync(profile).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { return; } done = true; }); } yield return(new WaitUntil(() => done == true)); done = false; Firebase.Auth.FirebaseUser currentUser = firebaseManager.auth.CurrentUser; currentUser.SendEmailVerificationAsync().ContinueWith(task => { done = true; }); yield return(new WaitUntil(() => done == true)); done = false; firebaseManager.reference.Child("Users").Child("Public Data").Child(publicUserData.name).Child(currentUser.UserId).Child("profile").SetRawJsonValueAsync(JsonUtility.ToJson(publicUserData)).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { return; } if (task.IsCompleted) { done = true; } }); yield return(new WaitUntil(() => done == true)); done = false; firebaseManager.reference.Child("Users").Child("Private Data").Child(publicUserData.name).Child(currentUser.UserId).Child("profile").SetRawJsonValueAsync(JsonUtility.ToJson(privateUserData)).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { return; } if (task.IsCompleted) { done = true; } }); yield return(new WaitUntil(() => done == true)); done = false; firebaseManager.reference.Child("Users").Child("Public Data").Child(publicUserData.name).Child(currentUser.UserId).Child("attendance").SetRawJsonValueAsync(JsonUtility.ToJson(new Attendance())).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { return; } if (task.IsCompleted) { done = true; } }); yield return(new WaitUntil(() => done == true)); done = false; firebaseManager.reference.Child("Email List").Child(inspirencEmail.text.Substring(0, inspirencEmail.text.IndexOf("@"))).SetValueAsync(inspirencEmail.text).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { return; } if (task.IsCompleted) { done = true; } }); yield return(new WaitUntil(() => done == true)); done = false; firebaseManager.disableLoadingScreen(); }
//CreateUser void public void CreateUser() { Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance; email = EmailField.text; password = PasswordField.text; username = NameField.text; usercity = LocationField.text; //Create user auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception); return; } // Firebase user has been created. Firebase.Auth.FirebaseUser newUser = task.Result; Debug.LogFormat("Firebase user created successfully: {0} ({1})", newUser.DisplayName, newUser.UserId); id = newUser.UserId; Debug.Log(id); //take inputs //Create data for user FirebaseDatabase database = FirebaseDatabase.DefaultInstance; database.RootReference.Child("users").Child(id).Child("username").SetValueAsync(username); database.RootReference.Child("users").Child(id).Child("location").SetValueAsync(usercity); database.RootReference.Child("users").Child(id).Child("completedachievment1").SetValueAsync(0); database.RootReference.Child("users").Child(id).Child("completedachievment2").SetValueAsync(0); database.RootReference.Child("users").Child(id).Child("completedachievment3").SetValueAsync(0); database.RootReference.Child("users").Child(id).Child("currentexp").SetValueAsync(0); database.RootReference.Child("users").Child(id).Child("level").SetValueAsync(0); database.RootReference.Child("users").Child(id).Child("mainachievement1").SetValueAsync(0); database.RootReference.Child("users").Child(id).Child("mainachievement2").SetValueAsync(0); database.RootReference.Child("users").Child(id).Child("plan1").SetValueAsync(0); database.RootReference.Child("users").Child(id).Child("likescount").SetValueAsync(0); //Send email verification Firebase.Auth.FirebaseUser user = auth.CurrentUser; user.SendEmailVerificationAsync().ContinueWith(goal => { if (goal.IsCanceled) { Debug.LogError("SendEmailVerificationAsync was canceled."); return; } if (goal.IsFaulted) { Debug.LogError("SendEmailVerificationAsync encountered an error: " + goal.Exception); return; } Debug.Log("Email sent successfully."); //Здесь можно показать диалоговое окно с информацией о том, что ссылка для подтверждения отправлена на почту }); }); }