public override void OnEnter() { ex = null; AuthManager.BeginProcess(); result = ProcessResult.Running; AuthManager.Instance.auth.SignInAnonymouslyAsync().ContinueWith(task => { if (task.IsFaulted || task.IsCanceled) { QEventExecutor.ExecuteInUpdate(() => { ex = AuthManager.GetFirebaseException(ex); AuthManager.FinishProcess(); result = ProcessResult.Failure; }); return; } QEventExecutor.ExecuteInUpdate(() => { Logger.Log("Anonymous SingIn Completed!", this, true); AuthManager.FinishProcess(); result = ProcessResult.Completed; }); }); }
public override void OnEnter() { AuthManager.BeginProcess(); result = ProcessResult.Running; cmd = AuthCheckCommand.Next; NetworkUtility.CheckInternet((bool internet) => { cmd = internet ? AuthCheckCommand.Next : AuthCheckCommand.Exit; AuthManager.FinishProcess(!internet, !internet ? new System.Exception("No internet connection") : null); result = ProcessResult.Completed; }); }
public override void Execute(AuthManager manager) { AuthManager.BeginProcess(); Checkdb(); }
protected override void OnInit(AuthManager manager) { RegisterFormButton.onClick.AddListener(() => { nav = emailNavigation.RegisterForm; UpdateLayout(); }); BackToSingInButton.onClick.AddListener(() => { nav = emailNavigation.LoginForm; UpdateLayout(); }); ForgotPasswordButton.onClick.AddListener(() => { nav = emailNavigation.ForgotPassword; UpdateLayout(); }); foreach (Button btn in BackButtons) { btn.onClick.AddListener(() => btn_back = true); } RecoverPasswordButton.onClick.AddListener(() => { result = ProcessResult.Running; if (!string.IsNullOrEmpty(Email_SingIn.text)) { Email_Recoverpassword.text = Email_SingIn.text; } AuthManager.BeginProcess(); AuthManager.Instance.auth.SendPasswordResetEmailAsync(Email_Recoverpassword.text).ContinueWith (task => { if (task.IsFaulted || task.IsCanceled) { QEventExecutor.ExecuteInUpdate(() => { ex = AuthManager.GetFirebaseException(task.Exception); AuthManager.FinishProcess(true, ex); result = ProcessResult.Failure; }); return; } QEventExecutor.ExecuteInUpdate(() => { Logger.Log("Password sent correctly", this, true); nav = emailNavigation.ForgotPasswordFinish; UpdateLayout(); AuthManager.FinishProcess(); result = ProcessResult.Running; }); }); }); RegisterButton.onClick.AddListener(() => { result = ProcessResult.Running; if (!string.IsNullOrEmpty(Password_Register.text) && string.Equals(Password_Register.text, Password_Register_c.text)) { if (AuthManager.Instance.IsAuthenticated) { if (AuthManager.Instance.auth.CurrentUser.IsAnonymous) { AuthManager.BeginProcess(); Credential ecred = EmailAuthProvider.GetCredential(Email_Register.text, Password_Register.text); AuthManager.Instance.auth.CurrentUser.LinkWithCredentialAsync(ecred).ContinueWith (task => { if (task.IsFaulted || task.IsCanceled) { QEventExecutor.ExecuteInUpdate(() => { ex = AuthManager.GetFirebaseException(task.Exception); AuthManager.FinishProcess(true, ex); result = ProcessResult.Failure; }); return; } QEventExecutor.ExecuteInUpdate(() => { Logger.Log("Link Account completed!", this, true); AuthManager.FinishProcess(); result = ProcessResult.Completed; }); }); } else { Logger.LogWarning("User is not anonymous!", this); ex = new System.ArgumentException("User is not anonymous!"); result = ProcessResult.Failure; } } else { AuthManager.BeginProcess(); AuthManager.Instance.auth.CreateUserWithEmailAndPasswordAsync(Email_Register.text, Password_Register.text).ContinueWith(task => { if (task.IsFaulted || task.IsCanceled) { QEventExecutor.ExecuteInUpdate(() => { ex = AuthManager.GetFirebaseException(task.Exception); AuthManager.FinishProcess(true, ex); result = ProcessResult.Failure; }); return; } QEventExecutor.ExecuteInUpdate(() => { AuthManager.FinishProcess(); uid = task.Result.UserId; Logger.Log("Create user with email done. id: " + uid, this, true); result = ProcessResult.Completed; }); }); } } else { ex = new System.ArgumentException("Passwords must match"); Logger.LogWarning(ex.Message, this); AuthManager.FinishProcess(true, ex); result = ProcessResult.Failure; } }); SingInButton.onClick.AddListener(() => { AuthManager.BeginProcess(); result = ProcessResult.Running; AuthManager.Instance.auth.SignInWithEmailAndPasswordAsync(Email_SingIn.text, Password_SingIn.text) .ContinueWith(task => { if (task.IsFaulted || task.IsCanceled) { QEventExecutor.ExecuteInUpdate(() => { ex = AuthManager.GetFirebaseException(task.Exception); AuthManager.FinishProcess(true, ex); result = ProcessResult.Failure; }); return; } QEventExecutor.ExecuteInUpdate(() => { Logger.Log("SingIn completed", this, true); AuthManager.FinishProcess(); result = ProcessResult.Completed; }); }); }); }
private void SetupNickname() { FirebaseUser usr = AuthManager.Instance.auth.CurrentUser; string username = textUsername.text.ToLower(); if (username.Length < MinimunUsernameLenght) { Logger.LogWarning("Nickname selected is too short", this); result = ProcessResult.None; AuthManager.FinishProcess(true, new QAuthException(QAuthErrorCode.SHORT_USERNAME)); return; } if (QWordFilter.IsValidString(username)) { result = ProcessResult.Running; AuthManager.BeginProcess(); QDataManager.Instance.NicknameValid(username, (bool m_result) => { if (m_result) { QDataManager.Instance.RegisterNickname(username, usr.UserId, () => { usr?.UpdateUserProfileAsync (new UserProfile() { DisplayName = username }).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { QEventExecutor.ExecuteInUpdate(() => { m_ex = AuthManager.GetFirebaseException(m_ex); Logger.LogError("Setup Profile Failure! " + m_ex, this); result = ProcessResult.Failure; AuthManager.FinishProcess(); }); return; } QEventExecutor.ExecuteInUpdate(() => { Logger.Log("Setup Profile Completed!", this, true); result = ProcessResult.Completed; textUsername.text = string.Empty; AuthManager.FinishProcess(); AuthManager.CompleteProfile(); }); }); }, (System.Exception ex) => { m_ex = ex; Logger.LogError("An error ocurrer at register nickname " + ex, this); result = ProcessResult.Failure; AuthManager.FinishProcess(); }); } else { Logger.LogWarning("Nickname already in the database", this); result = ProcessResult.Failure; AuthManager.FinishProcess(true, new QAuthException(QAuthErrorCode.USERNAME_EXISTS)); } }, (System.Exception ex) => { m_ex = ex; Logger.LogError("Error at checking nickname" + ex, this); result = ProcessResult.Failure; AuthManager.FinishProcess(); }); } else { Logger.LogWarning("Nickname selected is not valid", this); result = ProcessResult.None; AuthManager.FinishProcess(true, new QAuthException(QAuthErrorCode.INVALID_USERNAME)); } }