/// <summary> /// Send ui event to show account action attempt result /// </summary> /// <returns></returns> public IEnumerator HandleLoginAttempt() { NotificationManager.Instance.SetLoadingPanel(true); // wait until firebase finishes (had really unpredictable behavior if handled from within the WithFailure callback) yield return(new WaitUntil(() => attemptFinished)); NotificationManager.Instance.SetLoadingPanel(false); // send success notification or error message if (OnAccountActionAttempt != null) { if (attemptSuccess) { //OnAccountActionAttempt.Invoke("Login Successful"); //Disable(); SwitchToMainMenu("Login Successful"); } else { OnAccountActionAttempt.Invoke(errorMessage); } } attemptFinished = false; attemptSuccess = false; }
/// <summary> /// Attempts to create a new user with the given email and password by referencing LoginService static instance, will invoke ui notification with result /// </summary> public void RegisterNewUserWithEmail() { if (confirmPassword != password) { OnAccountActionAttempt?.Invoke("Confirmation password must match first password."); return; } if (loginAttempt != null && loginAttempt.Status == TaskStatus.Running) { return; } NotificationManager.Instance.SetLoadingPanel(true); loginAttempt = ReGenClient.Instance.Authentication.RegisterUserWithEmail(email, password) .Success(user => { NotificationManager.Instance.SetLoadingPanel(false); SwitchToMainMenu("Account registered"); }) .Failure(exception => { NotificationManager.Instance.SetLoadingPanel(false); OnAccountActionAttempt?.Invoke(exception.Message); }); }
public void SwitchToMainMenu(string transitionMessage) { OnAccountActionAttempt?.Invoke(transitionMessage); Disable(); /** * To-do: remove dependency on MainMenuManagerUI * (this class shouldn't know about other UI classes). */ MainMenuManagerUI.Instance.Enable(); }
/// <summary> /// Attempts to create a new user with the given email and password by referencing LoginService static instance, will invoke ui notification with result /// </summary> public void RegisterNewUserWithEmail() { if (confirmPassword != password) { errorMessage = "Confirmation password must match first password."; OnAccountActionAttempt?.Invoke(errorMessage); return; } // start coruoutine to handle attempt result ui notification if (attemptCo != null) { StopCoroutine(attemptCo); attemptCo = null; } attemptCo = StartCoroutine(HandleSignupAttempt()); attemptFinished = false; LoginService.Instance.RegisterUserWithEmail(email, password).WithSuccess(user => { attemptSuccess = true; attemptFinished = true; }) .WithFailure((FirebaseException exception) => { // parse error code to send to ui notification string errorStr = exception.GetAuthError().ToString(); //errorMessage = ""; //for (int i = 0; i < errorStr.Length; i++) //{ // errorMessage += (Char.IsUpper(errorStr[i]) && i > 0 // ? " " + errorStr[i].ToString() // : errorStr[i].ToString()); //} errorMessage = exception.Message; attemptSuccess = false; attemptFinished = true; }); }
/// <summary> /// Display a popup for event success or failure. /// </summary> /// <returns></returns> public IEnumerator HandleSignupAttempt() { NotificationManager.Instance.SetLoadingPanel(true); // wait until firebase finishes (had really unpredictable behavior if handled from within the WithFailure callback) yield return(new WaitUntil(() => attemptFinished)); NotificationManager.Instance.SetLoadingPanel(false); // send success notification or error message if (OnAccountActionAttempt != null) { OnAccountActionAttempt.Invoke( (attemptSuccess ? "Account registered" : errorMessage)); } attemptFinished = false; attemptSuccess = false; }
/// <summary> /// Attempts to log in user with the given email and password by referencing LoginService static instance, will invoke ui notification with result /// </summary> public void LogInWithEmail() { // start coruoutine to handle attempt result ui notification if (loginAttempt != null && loginAttempt.Status == TaskStatus.Running) { return; } NotificationManager.Instance.SetLoadingPanel(true); loginAttempt = ReGenClient.Instance.Authentication.SignInUserWithEmail(email, password) .Success(user => { NotificationManager.Instance.SetLoadingPanel(false); SwitchToMainMenu("Login Successful"); }) .Failure(exception => { NotificationManager.Instance.SetLoadingPanel(false); OnAccountActionAttempt?.Invoke(exception.Message); }); }
public void LogInWithFB() { Action <string> success = token => { ReGenClient.Instance.Authentication.SignInUserWithFacebook(token).Success(user => { NotificationManager.Instance.SetLoadingPanel(false); SwitchToMainMenu("Login Successful"); }).Failure(error => { NotificationManager.Instance.SetLoadingPanel(false); OnAccountActionAttempt?.Invoke(error.Message); }); }; FacebookManager.Instance.Login(success, error => { MainThreadTask.Run(async() => { NotificationManager.Instance.SetLoadingPanel(false); OnAccountActionAttempt?.Invoke(error); }); }); }