コード例 #1
0
        public void RegisterNickname(string nickname, string uid, System.Action OnComplete = null,
                                     System.Action <System.Exception> OnFailure            = null)
        {
            DatabaseReference           _ref     = FirebaseDatabase.DefaultInstance.GetReference(UsersNodePath).Child(uid);
            Dictionary <string, object> m_update = new Dictionary <string, object>();

            m_update.Add("username", nickname);

            _ref.UpdateChildrenAsync(m_update).ContinueWith(task =>
            {
                if (task.IsFaulted || task.IsCanceled)
                {
                    QEventExecutor.ExecuteInUpdate(() =>
                    {
                        Debug.LogError("[QDataManager] Update fail " + task.Exception);
                        OnFailure?.Invoke(task.Exception);
                    });
                    return;
                }

                QEventExecutor.ExecuteInUpdate(() =>
                {
                    Debug.Log("[QDataManager] Nickname register completed!");
                    OnComplete?.Invoke();
                });
            });
        }
コード例 #2
0
        public void RegisterPlayerToDatabase(UserPlayer player, System.Action OnComplete = null,
                                             System.Action <System.Exception> OnFalure   = null)
        {
            DatabaseReference _ref = FirebaseDatabase.DefaultInstance.GetReference(UsersNodePath).Child(player.userid);

            _ref.SetRawJsonValueAsync(JsonUtility.ToJson(player)).ContinueWith(task =>
            {
                if (task.IsCanceled || task.IsFaulted)
                {
                    QEventExecutor.ExecuteInUpdate(() =>
                    {
                        Debug.LogError("[QDataManager] Error at register user to database " + task.Exception);
                        OnFalure?.Invoke(task.Exception);
                    });

                    return;
                }

                QEventExecutor.ExecuteInUpdate(() =>
                {
                    Debug.Log("[QDataManager] Register to database Completed");
                    OnComplete?.Invoke();
                });
            });
        }
コード例 #3
0
ファイル: AnonymousMethod.cs プロジェクト: pedro15/QSocial
        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;
                });
            });
        }
コード例 #4
0
        public void GetPlayerFromId(string uid, System.Action <UserPlayer> OnComplete = null,
                                    System.Action <System.Exception> OnFailure        = null)
        {
            UserPlayer        user = null;
            DatabaseReference _ref = FirebaseDatabase.DefaultInstance.GetReference(UsersNodePath).Child(uid);

            _ref.GetValueAsync().ContinueWith(task =>
            {
                if (task.IsCanceled || task.IsFaulted)
                {
                    QEventExecutor.ExecuteInUpdate(() =>
                    {
                        Debug.LogError("Error executing query! " + task.Exception);
                        OnFailure?.Invoke(task.Exception);
                    });

                    return;
                }

                QEventExecutor.ExecuteInUpdate(() =>
                {
                    try
                    {
                        string json = task.Result.GetRawJsonValue();

                        var root = JSON.Parse(json);

                        JSONNode friends_Node = root["friends"];
                        string[] friends      = new string[friends_Node.Count];

                        for (int i = 0; i < friends.Length; i++)
                        {
                            friends[i] = friends_Node[i].Value;
                        }

                        user = new UserPlayer(root["username"].Value, uid, friends);

                        OnComplete?.Invoke(user);
                    }
                    catch (System.Exception ex)
                    {
                        OnFailure?.Invoke(new System.Exception("Invalid JSON from user request " + ex));
                    }
                });
            });
        }
コード例 #5
0
        public void SetCurrentUserData(string RawJSON, System.Action OnComplete   = null,
                                       System.Action <System.Exception> OnFailure = null)
        {
            if (AuthManager.Instance.IsAuthenticated)
            {
                string            uid  = AuthManager.Instance.auth.CurrentUser.UserId;
                DatabaseReference _ref = FirebaseDatabase.DefaultInstance.GetReference(CloudSaveNodePath).Child(uid);

                _ref.SetRawJsonValueAsync(RawJSON).ContinueWith(task =>
                {
                    if (task.IsFaulted || task.IsCanceled)
                    {
                        QEventExecutor.ExecuteInUpdate(() => OnFailure?.Invoke(task.Exception));
                        return;
                    }
                    QEventExecutor.ExecuteInUpdate(() => OnComplete?.Invoke());
                });
            }
            else
            {
                Debug.LogError("[QDataManager] User is not autenticated!");
            }
        }
コード例 #6
0
        public void GetCurrentUserData(System.Action <string> Response, System.Action <System.Exception> OnFailure = null)
        {
            if (AuthManager.Instance.IsAuthenticated)
            {
                string            uid  = AuthManager.Instance.auth.CurrentUser.UserId;
                DatabaseReference _ref = FirebaseDatabase.DefaultInstance.GetReference(CloudSaveNodePath).Child(uid);

                _ref.GetValueAsync().ContinueWith(task =>
                {
                    if (task.IsFaulted || task.IsCanceled)
                    {
                        QEventExecutor.ExecuteInUpdate(() => OnFailure?.Invoke(task.Exception));
                        return;
                    }
                    QEventExecutor.ExecuteInUpdate(() => Response.Invoke(task.Result.GetRawJsonValue()));
                });
            }
            else
            {
                OnFailure.Invoke(new System.ArgumentException("User is not autenticated"));
                Debug.LogError("[QDataManager:: GetCurrentUserData] User is not autenticated!");
            }
        }
コード例 #7
0
        public void NicknameValid(string nickname, System.Action <bool> Result,
                                  System.Action <System.Exception> OnFailure = null)
        {
            DatabaseReference _ref = FirebaseDatabase.DefaultInstance.GetReference(UsersNodePath);

            _ref.Child("username").EqualTo(nickname).GetValueAsync().ContinueWith(task =>
            {
                if (task.IsFaulted || task.IsCanceled)
                {
                    QEventExecutor.ExecuteInUpdate(() =>
                    {
                        Debug.LogError("[QDataManager] Error fetching usernames");
                        OnFailure?.Invoke(task.Exception);
                    });
                    return;
                }

                QEventExecutor.ExecuteInUpdate(() =>
                {
                    Result.Invoke(!task.Result.Exists);
                });
            });
        }
コード例 #8
0
ファイル: EmailMethod.cs プロジェクト: pedro15/QSocial
        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;
                    });
                });
            });
        }
コード例 #9
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));
            }
        }
コード例 #10
0
        private void HandleResult(IResult result)
        {
            Debug.Log("[FacebookAuth] Result: " + result);

            if (result == null)
            {
                ex   = new System.Exception("Error at login!");
                tres = ProcessResult.Failure;
                return;
            }

            // Some platforms return the empty string instead of null.
            if (!string.IsNullOrEmpty(result.Error))
            {
                ex   = new System.Exception(result.Error);
                tres = ProcessResult.Failure;
            }
            else if (result.Cancelled)
            {
                ex   = new System.Exception("LogIn cancelled");
                tres = ProcessResult.Failure;
            }
            else if (!string.IsNullOrEmpty(result.RawResult))
            {
                Debug.Log("[Facebook Auth] login OK!... Access token:: " + AccessToken.CurrentAccessToken.TokenString);

                Credential fbcredential = FacebookAuthProvider.GetCredential(AccessToken.CurrentAccessToken.TokenString);

                if (AuthManager.Instance.IsAuthenticated)
                {
                    if (AuthManager.Instance.auth.CurrentUser.IsAnonymous)
                    {
                        AuthManager.Instance.auth.CurrentUser.LinkWithCredentialAsync(fbcredential).ContinueWith(task =>
                        {
                            if (task.IsCanceled || task.IsFaulted)
                            {
                                QEventExecutor.ExecuteInUpdate(() =>
                                {
                                    ex = AuthManager.GetFirebaseException(task.Exception);
                                    Debug.LogError("[Facebok auth] An Error ocurred " + ex);
                                    tres = ProcessResult.Failure;
                                });
                                return;
                            }

                            if (task.IsCompleted)
                            {
                                QEventExecutor.ExecuteInUpdate(() =>
                                {
                                    Debug.Log("[Facebook Auth] Auth completed!");
                                    uid  = task.Result.UserId;
                                    tres = ProcessResult.Completed;
                                });
                            }
                        });
                    }
                    else
                    {
                        ex = new System.ArgumentException("User is not anonymous");
                        Debug.LogError("[FacebookAuth] User is not Anonymous!");
                        tres = ProcessResult.Failure;
                    }
                }
                else
                {
                    AuthManager.Instance.auth.SignInWithCredentialAsync(fbcredential).ContinueWith(task =>
                    {
                        if (task.IsCanceled || task.IsFaulted)
                        {
                            QEventExecutor.ExecuteInUpdate(() =>
                            {
                                ex = AuthManager.GetFirebaseException(task.Exception);
                                Debug.LogError("[Facebok auth] An Error ocurred " + ex);
                                tres = ProcessResult.Failure;
                            });
                            return;
                        }

                        if (task.IsCompleted)
                        {
                            QEventExecutor.ExecuteInUpdate(() =>
                            {
                                Debug.Log("[Facebook Auth] Register completed!");
                                uid  = task.Result.UserId;
                                tres = ProcessResult.Completed;
                            });
                        }
                    });
                }
            }
            else
            {
                ex   = new System.Exception("Empty Response");
                tres = ProcessResult.Failure;
            }

            Debug.Log("[Facebook AUth] result: " + result.ToString());
        }