Пример #1
0
    public void SetPlayerNameAndImage(string playerName, string imageUrl)
    {
        FirebaseUser user = FirebaseAuth.DefaultInstance.CurrentUser;

        if (user != null)
        {
            UserProfile profile = new UserProfile
            {
                DisplayName = playerName,
                PhotoUrl    = new System.Uri(imageUrl),
            };
            user.UpdateUserProfileAsync(profile).ContinueWith(task => {
                if (task.IsCanceled)
                {
                    Debug.LogError("UpdateUserProfileAsync was canceled.");
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.LogError("UpdateUserProfileAsync encountered an error: " + task.Exception);
                    return;
                }

                Debug.Log("User profile updated successfully.");
            });
        }
    }
    public IEnumerator registrarNovoUsuario()
    {
        string meuLogin     = login.text;
        string minhaSenha   = senha.text;
        var    RegisterTask = auth.CreateUserWithEmailAndPasswordAsync(meuLogin, minhaSenha);

        yield return(new WaitUntil(predicate: () => RegisterTask.IsCompleted));

        if (RegisterTask.Exception != null)
        {
        }
        else
        {
            user = RegisterTask.Result;

            if (user != null)
            {
                UserProfile profile = new UserProfile {
                    DisplayName = meuLogin
                };
                var ProfileTask = user.UpdateUserProfileAsync(profile);
                yield return(new WaitUntil(predicate: () => ProfileTask.IsCompleted));

                if (ProfileTask.Exception != null)
                {
                }
                else
                {
                    print("REGISTRADO COM SUCESSO!");
                }
            }
        }
    }
    public static void AuthName(string Name)
    {
        FirebaseUser User = Auth.CurrentUser;

        if (User != null)
        {
            UserProfile Profile = new UserProfile
            {
                DisplayName = Name,
                // PhotoUrl = new System.Uri(""),
            };
            User.UpdateUserProfileAsync(Profile).ContinueWith(task =>
            {
                if (task.IsCanceled)
                {
                    Debug.LogError("Firebase Auth - UpdateUserProfileAsync foi cancelado.");
                    // TecWolf.System.SystemInterface.Alert("A atualização de conta foi cancelada.");
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.LogError("Firebase Auth - UpdateUserProfileAsync encontrou um erro: " + task.Exception);
                    // TecWolf.System.SystemInterface.Alert("Erro ao atualizar conta.");
                    return;
                }

                Debug.Log("Firebase Auth - Usuário atualizado com sucesso.");
                // TecWolf.System.SystemInterface.Alert("Conta atualizada com sucesso.");
            });
        }
    }
Пример #4
0
    private IEnumerator _registrNewAccount(string login, string email, string password)
    {
        var registrTask = authentication.CreateUserWithEmailAndPasswordAsync(email, password);

        yield return(new WaitUntil(() => registrTask.IsCompleted));

        if (registrTask.Exception != null)
        {
            Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + registrTask.Exception);
            //Message.Instance.MessageToUser("Connection failed", MessageKind.Warning);
            FirebaseException fbExeption = registrTask.Exception.GetBaseException() as FirebaseException;
            AuthError         errorCode  = (AuthError)fbExeption.ErrorCode;
            switch (errorCode)
            {
            case AuthError.MissingEmail:
                Message.MessageToUser("Missing Email!", MessageKind.Warning);
                break;

            case AuthError.MissingPassword:
                Message.MessageToUser("Missing password!", MessageKind.Warning);
                break;

            case AuthError.WeakPassword:
                Message.MessageToUser("Password is too weak!", MessageKind.Warning);
                break;

            case AuthError.EmailAlreadyInUse:
                Message.MessageToUser("Email already in use!", MessageKind.Warning);
                break;

            default:
                Message.MessageToUser("Registration failed!", MessageKind.Warning);
                break;
            }
        }
        else
        {
            user = registrTask.Result;
            if (user != null)
            {
                UserProfile profile = new UserProfile {
                    DisplayName = login
                };
                var profileTask = user.UpdateUserProfileAsync(profile);
                yield return(new WaitUntil(() => profileTask.IsCompleted));

                if (profileTask.Exception != null)
                {
                    Debug.LogError("UpdateUserProfileAsync encountered an error: " + profileTask.Exception);
                    Message.MessageToUser("Authentication failed", MessageKind.Warning);
                }
                else
                {
                    Debug.LogFormat("Firebase user created successfully: {0} ({1})", user.DisplayName, user.UserId);
                    Message.MessageToUser("Registration successful!", MessageKind.Confirm);
                    SwitchToLoginMenu();
                }
            }
        }
    }
Пример #5
0
 public async void UpdateUserProfile(FirebaseUser user)
 {
     UserProfile profile = new UserProfile {
         DisplayName = user.DisplayName
     };
     await user.UpdateUserProfileAsync(profile).ContinueWith(profileTask =>
     {
         if (profileTask.IsFaulted)
         {
         }
         else if (profileTask.IsCompleted)
         {
             if (profileTask.Exception != null)
             {
                 Debug.LogWarning(message: $"failed to register task with {profileTask.Exception}");
                 FirebaseException firebaseEx = profileTask.Exception.GetBaseException() as FirebaseException;
                 AuthError errorCode          = (AuthError)firebaseEx.ErrorCode;
                 Debug.Log("Username set failed");
             }
             else
             {
                 Debug.Log("ALL OK WITH AUTHENTICATION");
                 PostUserWithFireBaseRT(userName, json);
             }
         }
     });
 }
Пример #6
0
    public void clickOnUpdateAvatar()
    {
        String       nickname    = this.nickname.text;
        FirebaseUser currentUser = UserLogged.getLoggedUser();

        if (!string.IsNullOrEmpty(nickname))
        {
            if (currentUser != null)
            {
                Firebase.Auth.UserProfile profile = new Firebase.Auth.UserProfile
                {
                    DisplayName = nickname,
                };
                currentUser.UpdateUserProfileAsync(profile).ContinueWith(task => {
                    if (task.IsCanceled)
                    {
                        Debug.LogError("UpdateUserProfileAsync was canceled.");
                        return;
                    }
                    if (task.IsFaulted)
                    {
                        infoMessage.faceColor = new Color32(255, 0, 0, 255);
                        AggregateException ex = task.Exception as AggregateException;
                        if (ex != null)
                        {
                            Firebase.FirebaseException fbEx = null;
                            foreach (Exception e in ex.InnerExceptions)
                            {
                                fbEx = e as Firebase.FirebaseException;
                                if (fbEx != null)
                                {
                                    break;
                                }
                            }

                            if (fbEx != null)
                            {
                                infoMessage.text = fbEx.Message;
                            }
                        }
                        return;
                    }

                    infoMessage.faceColor = new Color32(0, 255, 0, 255);
                    infoMessage.text      = "User profile updated successfuly!";
                    GameObject gameObj    = GameObject.Find("User");
                    DontDestroyOnLoad(gameObj);
                    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
                });
            }
        }
        else
        {
            infoMessage.faceColor = new Color32(255, 0, 0, 255);
            infoMessage.text      = "Please enter a nickname!";
        }
    }
        private void UpdateUserProfileAsync(string username)
        {
            Log("UpdateUserProfileAsync");
            if (auth.CurrentUser == null)
            {
                Log("Not signed in, unable to update user profile");
                return;
            }

            Log("Updating user profile");

            user = auth.CurrentUser;
            if (user != null)
            {
                Firebase.Auth.UserProfile profile = new Firebase.Auth.UserProfile
                {
                    DisplayName = username,
                    PhotoUrl    = user.PhotoUrl,
                };

                user.UpdateUserProfileAsync(profile).ContinueWith(
                    task =>
                {
                    if (task.IsCanceled)
                    {
                        Log("UpdateUserProfileAsync was canceled.");
                        return;
                    }
                    if (task.IsFaulted)
                    {
                        Log("UpdateUserProfileAsync encountered an error: " + task.Exception);
                        return;
                    }
                    if (task.IsCompleted)
                    {
                        Log("User profile updated completed");
                    }

                    user = auth.CurrentUser;
                }
                    );
            }
        }
Пример #8
0
    /// <summary>
    /// perform updating of firebase user's profile information like display name
    /// </summary>
    /// <param name="displayName">user's display name</param>
    public void updateUserProfile(string displayName)
    {
        FirebaseUser user    = getFirebaseUser();
        UserProfile  profile = new Firebase.Auth.UserProfile
        {
            DisplayName = displayName,
        };

        user.UpdateUserProfileAsync(profile).ContinueWithOnMainThread(task =>
        {
            string message = readError(task);
            if (message != null)
            {
                return;
            }

            Debug.Log("updateProfile: successfully.");
        });
    }
Пример #9
0
    // FirebaseAuth에 사용자 이름 등록
    private void UpdateUserName(FirebaseUser newUser)
    {
        UserProfile profile = new UserProfile {
            DisplayName = nickNameField.text
        };

        newUser.UpdateUserProfileAsync(profile).ContinueWith(task => {
            if (task.IsCanceled)
            {
                Debug.LogError("Setting DisplayName was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("Setting DisplayName encountered an error: " + task.Exception);
                return;
            }

            Debug.LogFormat("Successfully created. Welcome, {0}({1})!", newUser.DisplayName, newUser.Email);
        });
    }
Пример #10
0
        ///<summary>
        ///Tries to create an account for the user in player accounts (now using firebase as of nov '19)
        ///</summary>
        public async static void TryCreateAccount(string proposedName, string _password, string emailAcc,
                                                  Action <CharacterSettings> callBack, Action <string> errorCallBack)
        {
            try
            {
                FirebaseUser user = await FirebaseAuth.DefaultInstance.CreateUserWithEmailAndPasswordAsync(emailAcc, _password);

                await user.SendEmailVerificationAsync();

                UserProfile profile = new UserProfile
                {
                    DisplayName = proposedName,
                    PhotoUrl    = null
                };

                await user.UpdateUserProfileAsync(profile);

                Logger.LogFormat($"Firebase user created successfully: {proposedName}",
                                 Category.DatabaseAPI);

                var newCharacter = new CharacterSettings
                {
                    Name     = StringManager.GetRandomMaleName(),
                    username = proposedName
                };

                callBack.Invoke(newCharacter);
            }
            catch (AggregateException ex)
            {
                var innerEx = ex.Flatten().InnerExceptions[0];
                Logger.LogError($"Failed to sign up {innerEx.Message}");
                errorCallBack.Invoke(innerEx.Message);
            }
            catch (Exception ex)
            {
                Logger.LogError($"Failed to sign up {ex.Message}");
                errorCallBack.Invoke(ex.Message);
            }
        }
Пример #11
0
    private IEnumerator UpdateUsernameAuth(string _username)
    {
        //Create a user profile and set the username
        UserProfile profile = new UserProfile {
            DisplayName = _username
        };

        //Call the Firebase auth update user profile function passing the profile with the username
        var ProfileTask = User.UpdateUserProfileAsync(profile);

        //Wait until the task completes
        yield return(new WaitUntil(predicate: () => ProfileTask.IsCompleted));

        if (ProfileTask.Exception != null)
        {
            Debug.LogWarning(message: $"Failed to register task with {ProfileTask.Exception}");
        }
        else
        {
            //Auth username is now updated
        }
    }
Пример #12
0
    public void DisplayNameChange()
    {
        if (user != null)
        {
            Firebase.Auth.UserProfile profile = new Firebase.Auth.UserProfile {
                DisplayName = displayNameInputField.text
            };
            user.UpdateUserProfileAsync(profile).ContinueWith(task => {
                if (task.IsCanceled)
                {
                    Debug.LogError("UpdateUserProfileAsync was canceled.");
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.LogError("UpdateUserProfileAsync encountered an error: " + task.Exception);
                    return;
                }

                Debug.Log("User profile updated successfully.");
                Debug.Log(user.DisplayName);
            });
        }
    }
Пример #13
0
    private void AuthStateChanged(object sender, System.EventArgs eventArgs)
    {
        if (auth.CurrentUser == user)
        {
            return;
        }

        var signedIn = user != auth.CurrentUser && auth.CurrentUser != null;

        if (!signedIn && user != null)
        {
            Debug.Log("Signed out " + user.UserId);
        }
        user = auth.CurrentUser;
        if (signedIn)
        {
            Debug.Log("Signed in " + user.UserId);
            Firebase.Auth.UserProfile profile = new Firebase.Auth.UserProfile {
                DisplayName = "Kyle Gray",
            };
            user.UpdateUserProfileAsync(profile).ContinueWith(a => { });
            SceneManager.LoadScene("POIPlacement");
        }
    }
    private IEnumerator Register(string _email, string _password, string _username)
    {
        if (_username == "")
        {
            //If the username field is blank show a warning
            warningRegisterText.text = "Missing Username";
        }
        else if (passwordRegisterField.text != passwordRegisterVerifyField.text)
        {
            //If the password does not match show a warning
            warningRegisterText.text = "Password Does Not Match!";
        }
        else
        {
            //Call the Firebase auth signin function passing the email and password
            var RegisterTask = auth.CreateUserWithEmailAndPasswordAsync(_email, _password);
            //Wait until the task completes
            yield return(new WaitUntil(predicate: () => RegisterTask.IsCompleted));

            if (RegisterTask.Exception != null)
            {
                //If there are errors handle them
                Debug.LogWarning(message: $"Failed to register task with {RegisterTask.Exception}");
                FirebaseException firebaseEx = RegisterTask.Exception.GetBaseException() as FirebaseException;
                AuthError         errorCode  = (AuthError)firebaseEx.ErrorCode;

                string message = "Register Failed!";
                switch (errorCode)
                {
                case AuthError.MissingEmail:
                    message = "Missing Email";
                    break;

                case AuthError.MissingPassword:
                    message = "Missing Password";
                    break;

                case AuthError.WeakPassword:
                    message = "Weak Password";
                    break;

                case AuthError.EmailAlreadyInUse:
                    message = "Email Already In Use";
                    break;
                }
                warningRegisterText.text = message;
            }
            else
            {
                //User has now been created
                //Now get the result
                User = RegisterTask.Result;

                if (User != null)
                {
                    //Create a user profile and set the username
                    UserProfile profile = new UserProfile {
                        DisplayName = _username
                    };

                    //Call the Firebase auth update user profile function passing the profile with the username
                    var ProfileTask = User.UpdateUserProfileAsync(profile);
                    //Wait until the task completes
                    yield return(new WaitUntil(predicate: () => ProfileTask.IsCompleted));

                    if (ProfileTask.Exception != null)
                    {
                        //If there are errors handle them
                        Debug.LogWarning(message: $"Failed to register task with {ProfileTask.Exception}");
                        FirebaseException firebaseEx = ProfileTask.Exception.GetBaseException() as FirebaseException;
                        AuthError         errorCode  = (AuthError)firebaseEx.ErrorCode;
                        warningRegisterText.text = "Username Set Failed!";
                    }
                    else
                    {
                        //Username is now set
                        //Now return to login screen
                        UIManager.instance.LoginScreen();
                        warningRegisterText.text = "";
                    }
                }
            }
        }
    }
Пример #15
0
    public IEnumerator Register(string _email, string _password, string _displayName)
    {
        LoadingScreen.Instance.Show("Signing up...");
        yield return(new WaitUntil(() => auth != null));

        var RegisterTask = auth.CreateUserWithEmailAndPasswordAsync(_email, _password);

        yield return(new WaitUntil(predicate: () => RegisterTask.IsCompleted));

        LoadingScreen.Instance.Hide();
        if (RegisterTask.Exception != null)
        {
            Debug.LogWarning(message: $"Failed to register task with {RegisterTask.Exception}");
            FirebaseException firebaseEx = RegisterTask.Exception.GetBaseException() as FirebaseException;
            AuthError         errorCode  = (AuthError)firebaseEx.ErrorCode;
            string            message    = "Register Failed!";
            switch (errorCode)
            {
            case AuthError.MissingEmail:
                message = "Missing Email";
                break;

            case AuthError.MissingPassword:
                message = "Missing Password";
                break;

            case AuthError.WeakPassword:
                message = "Weak Password";
                break;

            case AuthError.EmailAlreadyInUse:
                message = "Email Already In Use";
                break;
            }
            ILogger.Instance.ShowMessage(message, LoggerType.error);
        }
        else
        {
            User = RegisterTask.Result;
            if (User != null)
            {
                //Create a user profile and set the username
                UserProfile profile = new UserProfile {
                    DisplayName = _displayName
                };

                //Call the Firebase auth update user profile function passing the profile with the username
                var ProfileTask = User.UpdateUserProfileAsync(profile);
                //Wait until the task completes
                yield return(new WaitUntil(predicate: () => ProfileTask.IsCompleted));

                if (ProfileTask.Exception != null)
                {
                    //If there are errors handle them
                    Debug.LogWarning(message: $"Failed to register task with {ProfileTask.Exception}");
                    FirebaseException firebaseEx = ProfileTask.Exception.GetBaseException() as FirebaseException;
                    AuthError         errorCode  = (AuthError)firebaseEx.ErrorCode;
                    ILogger.Instance.ShowMessage("Diplay Name Set Failed!", LoggerType.error);
                }
                else
                {
                    PlayerPrefs.SetString(Constants.EMAIL_PREFS, _email);
                    PlayerPrefs.SetString(Constants.PASSWORD_PREFS, _password);
                    LoginScreenUI.Instance.AfterLogin();
                }
            }
        }
    }
Пример #16
0
    private IEnumerator Register(string _email, string _password, string _username)
    {
        if (!validateEmail(_email))
        {
            Debug.Log("이메일 형식이 아닙니다.");
        }
        if (_username == "")
        {
            warningRegisterText.text = "Missing Username";
        }
        else if (passwordRegisterField.text != passwordRegisterVerifyField.text)
        {
            warningRegisterText.text = "Password Does Not Match!";
        }
        else
        {
            var RegisterTask = auth.CreateUserWithEmailAndPasswordAsync(_email, _password);

            yield return(new WaitUntil(predicate: () => RegisterTask.IsCompleted));

            if (RegisterTask.Exception != null)
            {
                Debug.LogWarning(message: $"Failed to register task with {RegisterTask.Exception}");
                FirebaseException firebaseEx = RegisterTask.Exception.GetBaseException() as FirebaseException;
                AuthError         errorCode  = (AuthError)firebaseEx.ErrorCode;

                string message = "Register Failed!";
                switch (errorCode)
                {
                case AuthError.MissingEmail:
                    message = "Missing Email";
                    break;

                case AuthError.MissingPassword:
                    message = "Missing Password";
                    break;

                case AuthError.WeakPassword:
                    message = "Weak Password";
                    break;

                case AuthError.EmailAlreadyInUse:
                    message = "Email Already In Use";
                    break;
                }
                warningRegisterText.text = message;
            }
            else
            {
                User = RegisterTask.Result;
                if (User != null)
                {
                    UserProfile profile = new UserProfile {
                        DisplayName = _username
                    };

                    var ProfileTask = User.UpdateUserProfileAsync(profile);

                    yield return(new WaitUntil(predicate: () => ProfileTask.IsCompleted));

                    if (ProfileTask.Exception != null)
                    {
                        Debug.LogWarning(message: $"Failed to register task with {ProfileTask.Exception}");
                        FirebaseException firebaseEx = ProfileTask.Exception.GetBaseException() as FirebaseException;
                        AuthError         errorCode  = (AuthError)firebaseEx.ErrorCode;
                        warningRegisterText.text = "Username Set Failed!";
                    }
                    else
                    {
                        warningRegisterText.text = "";
                        GameObject.Find("UI_Manager").GetComponent <UIManager>().LoginScreen();
                    }
                }
            }
        }
    }
Пример #17
0
    IEnumerator Register(string email, string password, string username)
    {
        if (username == "")
        {
            warningRegText.text = "No username";
        }
        else if (passwordRegField.text != passwordRegVerifyField.text)
        {
            warningRegText.text = "Password donesn't match";
        }
        else
        {
            var registerTask = auth.CreateUserWithEmailAndPasswordAsync(email, password);
            yield return(new WaitUntil(predicate: () => registerTask.IsCompleted));

            if (registerTask.Exception != null)
            {
                // Register error
                Debug.LogWarning(message: $"Failed to register with {registerTask.Exception}");
                FirebaseException firebaseEx = (FirebaseException)registerTask.Exception.GetBaseException();
                AuthError         errorCode  = (AuthError)firebaseEx.ErrorCode;

                string message = "Failed to register";
                switch (errorCode)
                {
                case AuthError.MissingEmail:
                    message = "Enter email";
                    break;

                case AuthError.MissingPassword:
                    message = "Enter a password";
                    break;

                case AuthError.WeakPassword:
                    message = "Password too weak";
                    break;

                case AuthError.EmailAlreadyInUse:
                    message = "Email already in use";
                    break;

                default:
                    message = "Error idk why";
                    break;
                }
                warningRegText.text = message;
            }
            else
            {
                // User created!
                user = registerTask.Result;
                if (user != null)
                {
                    // Create user profile and set username
                    UserProfile profile = new UserProfile {
                        DisplayName = username
                    };
                    var profileTask = user.UpdateUserProfileAsync(profile);
                    yield return(new WaitUntil(predicate: () => profileTask.IsCompleted));

                    if (profileTask.Exception != null)
                    {
                        // Any errors?
                        Debug.LogWarning(message: $"Failed to register task with {profileTask.Exception}");
                        FirebaseException fireBaseEx = (FirebaseException)profileTask.Exception.GetBaseException();
                        AuthError         errorCode  = (AuthError)fireBaseEx.ErrorCode;
                        warningRegText.text = "Setting username error!";
                    }
                    else
                    {
                        var uiMan = uiManager.GetComponent <UIManager>();
                        uiMan.EnableProfilePage();
                        uiMan.InitiateProfilePage(username, email);
                        Debug.Log("IT WORKED!" + " Username: "******"";
                    }
                }
            }
        }
    }
Пример #18
0
    private IEnumerator Register(string _email, string _password, string _username)
    {
        if (_username == "")
        {
            warningRegisterText.text = "Digite o usuario";
        }
        else if (passwordRegisterField.text != passwordRegisterVerifyField.text)
        {
            warningRegisterText.text = "Senha não corresponde";
        }
        else
        {
            var RegisterTask = auth.CreateUserWithEmailAndPasswordAsync(_email, _password);
            yield return(new WaitUntil(predicate: () => RegisterTask.IsCompleted));

            if (RegisterTask.Exception != null)
            {
                Debug.LogWarning(message: $"Failed to register task with {RegisterTask.Exception}");
                FirebaseException firebaseEx = RegisterTask.Exception.GetBaseException() as FirebaseException;
                AuthError         errorCode  = (AuthError)firebaseEx.ErrorCode;

                string message = "Verifique seu email ([email protected])";
                switch (errorCode)
                {
                case AuthError.MissingEmail:
                    message = "Digite o E-mail";
                    break;

                case AuthError.MissingPassword:
                    message = "Digite a senha";
                    break;

                case AuthError.WeakPassword:
                    message = "A senha deve ter pelo menos seis caracteres";
                    break;

                case AuthError.EmailAlreadyInUse:
                    message = "Email já em uso";
                    break;
                }
                warningRegisterText.text = message;
            }
            else
            {
                User = RegisterTask.Result;

                if (User != null)
                {
                    UserProfile profile = new UserProfile {
                        DisplayName = _username
                    };

                    var ProfileTask = User.UpdateUserProfileAsync(profile);
                    yield return(new WaitUntil(predicate: () => ProfileTask.IsCompleted));

                    if (ProfileTask.Exception != null)
                    {
                        Debug.LogWarning(message: $"Failed to register task with {ProfileTask.Exception}");
                        FirebaseException firebaseEx = ProfileTask.Exception.GetBaseException() as FirebaseException;
                        AuthError         errorCode  = (AuthError)firebaseEx.ErrorCode;
                        warningRegisterText.text = "Username Set Failed!";
                    }
                    else
                    {
                        UIManager.instance.LoginScreen();
                        warningRegisterText.text = "";
                    }
                }
            }
        }
    }
Пример #19
0
    private IEnumerator Register(string _email, string _password, string _username)
    {
        if (_username == "")
        {
            warningLoginText.text = "Missing Username";
        }
        else if (passwordRegisterField.text != passwordVerifyRegisterField.text)
        {
            warningLoginText.text = "Password Does Not Match!";
        }
        else
        {
            var RegisterTask = auth.CreateUserWithEmailAndPasswordAsync(_email, _password);
            yield return(new WaitUntil(predicate: () => RegisterTask.IsCompleted));

            if (RegisterTask.Exception != null)
            {
                Debug.LogWarning(message: $"Failed to register task with {RegisterTask.Exception}");
                FirebaseException firebaseEx = RegisterTask.Exception.GetBaseException() as FirebaseException;
                AuthError         errorCode  = (AuthError)firebaseEx.ErrorCode;

                string message = "Register Failed!";
                switch (errorCode)
                {
                case AuthError.MissingEmail:
                    message = "Missing Email";
                    break;

                case AuthError.MissingPassword:
                    message = "Missing Password";
                    break;

                case AuthError.WeakPassword:
                    message = "Weak Password";
                    break;

                case AuthError.InvalidEmail:
                    message = "Email Already In Use";
                    break;
                }
                warningLoginText.text = message;
            }
            else
            {
                User = RegisterTask.Result;
                if (User != null)
                {
                    UserProfile profile = new UserProfile {
                        DisplayName = _username
                    };
                    var ProfileTask = User.UpdateUserProfileAsync(profile);
                    yield return(new WaitUntil(predicate: () => ProfileTask.IsCompleted));

                    if (ProfileTask.Exception != null)
                    {
                        Debug.LogWarning(message: $"Failed to register task with {ProfileTask.Exception}");
                        FirebaseException firebaseEx = ProfileTask.Exception.GetBaseException() as FirebaseException;
                        AuthError         errorCode  = (AuthError)firebaseEx.ErrorCode;
                        warningLoginText.text = "Username Set Failed!";
                    }
                    else
                    {
                        //Username is now set
                        reference.Child("Users").Child(User.DisplayName).Child("username").SetValueAsync(User.DisplayName);
                        LoginObj.SetActive(false);
                        RegisterObj.SetActive(true);
                        SwitchText.text       = "Войти";
                        warningLoginText.text = "";
                    }
                }
            }
        }
    }
Пример #20
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));
            }
        }