예제 #1
0
    IEnumerator AddUserAux(string email, string password, Delegates.CreateNewUser success, Delegates.GeneralListenerFail fail)
    {
        WWWForm form = new WWWForm();

        form.AddField("email", email);
        form.AddField("password", password);

        using (UnityWebRequest w = UnityWebRequest.Post(addUserURL, form)) {
            yield return(w.Send());

            if (w.isNetworkError || w.isHttpError)
            {
                Debug.Log(w.error);
                fail(w.error.ToString());
            }
            else
            {
                Debug.Log("User created! id: " + w.downloadHandler.text);
                var id          = w.downloadHandler.text.Split(':');
                var idFormatted = id [1].Replace("{", "");
                idFormatted = idFormatted.Replace("}", "");
                idFormatted = idFormatted.Replace("\"", "");
                success(idFormatted);
            }
        }
    }
    public void CreateNewUserWithEmailAndPassword(string name, string phone, string email, string password, Constants.UserType userType, Delegates.CreateNewUser success, Delegates.GeneralListenerFail fail)
    {
        auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
            if (task.IsCanceled)
            {
                Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");
                fail("Criação cancelada");
                return;
            }
            if (task.IsFaulted)
            {
                fail(GetErrorMessage(task.Exception.InnerExceptions [0] as FirebaseException));
                Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception);
                return;
            }

            // Firebase user has been created.
            user = task.Result;
            if (userType == Constants.UserType.User)
            {
                DataManager.currentUser = FireBaseManager.GetFireBaseInstance().CreateNewUser(auth.CurrentUser.UserId, name, phone);
            }

            var profile = new Firebase.Auth.UserProfile {
                DisplayName = name
            };
            UpdateUserProfile(profile);

            success(user.UserId);
            Debug.LogFormat("Firebase user created successfully: {0} ({1})",
                            user.DisplayName, user.UserId);
        });
    }
    public void CreateNewCompanyWithEmailAndPassword(string companyName, string email, string password, Delegates.CreateNewUser success, Delegates.GeneralListenerFail fail)
    {
        auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
            if (task.IsCanceled)
            {
                Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");
                fail("Criação cancelada");
                return;
            }
            if (task.IsFaulted)
            {
                fail(GetErrorMessage(task.Exception.InnerExceptions [0] as FirebaseException));
                Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception);
                return;
            }

            // Firebase user has been created.
            user = task.Result;

            var profile = new Firebase.Auth.UserProfile {
                DisplayName = companyName
            };
            UpdateUserProfile(profile);

            success(user.UserId);
            Debug.LogFormat("Firebase company created successfully: {0} ({1})",
                            user.DisplayName, user.UserId);
        });
    }
예제 #4
0
 public void AddUser(string email, string password, Delegates.CreateNewUser success, Delegates.GeneralListenerFail fail)
 {
     StartCoroutine(AddUserAux(email, password, success, fail));
 }