示例#1
0
        public override void OnUpdate()
        {
            if (Input.GetKeyDown(KeyCode.Escape) || btn_back)
            {
                if (AuthManager.Instance.IsAuthenticated && AuthManager.Instance.auth.CurrentUser.IsAnonymous)
                {
                    nav = emailNavigation.None;
                    UpdateLayout();
                    BackResult = true;
                }
                else
                {
                    switch (nav)
                    {
                    case emailNavigation.ForgotPassword:

                        nav = emailNavigation.LoginForm;

                        break;

                    case emailNavigation.ForgotPasswordFinish:

                        nav = emailNavigation.ForgotPassword;

                        break;

                    case emailNavigation.RegisterForm:

                        nav = emailNavigation.LoginForm;

                        break;

                    case emailNavigation.LoginForm:

                        nav = emailNavigation.None;

                        break;
                    }
                    UpdateLayout();
                    BackResult = (nav != emailNavigation.None) ? false : true;
                }

                btn_back = false;
            }
            else if (Input.GetKeyUp(KeyCode.Escape) || !btn_back)
            {
                BackResult = false;
            }
        }
示例#2
0
        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;
                    });
                });
            });
        }
示例#3
0
 public void HideUI()
 {
     nav        = emailNavigation.None;
     BackResult = false;
     UpdateLayout();
 }
示例#4
0
 public void DisplayUI(bool IsAnonymous)
 {
     nav = IsAnonymous ? emailNavigation.RegisterForm : emailNavigation.LoginForm;
     UpdateLayout();
 }