예제 #1
0
        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));
            }
        }