Пример #1
0
    IEnumerator Login(string _userId, string _password)
    {
        WWWForm form = new WWWForm();

        form.AddField("userId", _userId);
        form.AddField("password", _password);

        using (UnityWebRequest www = UnityWebRequest.Post(getUsersURL, form))
        {
            yield return(www.SendWebRequest());

            if (www.result != UnityWebRequest.Result.Success)
            {
                Debug.Log(www.error);
            }
            else
            {
                Debug.Log(www.downloadHandler.text);
                ClearAllFeilds();

                photonManager.Connect();
            }
        }
    }
Пример #2
0
    private IEnumerator Login(string _email, string _password)
    {
        //Call the Firebase auth signin function passing the email and password

        //추후에 삭제하셈
#if UNITY_EDITOR
        var LoginTask = auth.SignInWithEmailAndPasswordAsync("*****@*****.**", "123456");
#else
        var LoginTask = auth.SignInWithEmailAndPasswordAsync(_email, _password);
#endif
        //Wait until the task completes
        yield return(new WaitUntil(predicate: () => LoginTask.IsCompleted));

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

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

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

            case AuthError.WrongPassword:
                message = "Wrong Password";
                break;

            case AuthError.InvalidEmail:
                message = "Invalid Email";
                break;

            case AuthError.UserNotFound:
                message = "Account does not exist";
                break;
            }
            warningLoginText.text = message;
        }
        else
        {
            //User is now logged in
            //Now get the result
            User = LoginTask.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})", User.DisplayName, User.Email);
            warningLoginText.text = "";
            confirmLoginText.text = "Logged In";
            StartCoroutine(LoadUserData());

            yield return(new WaitForSeconds(2));

            username           = User.DisplayName;
            usernameField.text = User.DisplayName;
            UIManager.instance.LobbyScreen(); // Change to user data UI
            confirmLoginText.text = "";
            ClearLoginFeilds();
            ClearRegisterFeilds();

            connected = true;

            photonManager.Connect();
        }
    }