コード例 #1
0
 /// <summary>
 /// 非同期処理でオブジェクトの保存を行います。<br/>
 /// SaveAsync()を実行してから編集などをしていなく、保存をする必要が無い場合は通信を行いません。<br/>
 /// オブジェクトIDが登録されていない新規オブジェクトなら登録を行います。<br/>
 /// オブジェクトIDが登録されている既存オブジェクトなら更新を行います。<br/>
 /// </summary>
 /// <returns>もとのオブジェクト</returns>
 public static IObservable <NCMBUser> SaveAsyncAsStream(this NCMBUser origin)
 {
     return(Observable.Create <NCMBUser>(observer =>
     {
         var gate = new object();
         var isDisposed = false;
         origin.SaveAsync(error =>
         {
             lock (gate)
             {
                 if (isDisposed)
                 {
                     return;
                 }
                 if (error == null)
                 {
                     observer.OnNext(origin);
                     observer.OnCompleted();
                 }
                 else
                 {
                     observer.OnError(error);
                 }
             }
         });
         return Disposable.Create(() =>
         {
             lock (gate)
             {
                 isDisposed = true;
             }
         });
     }));
 }
コード例 #2
0
    public IEnumerator LogInWithAuthDataAsyncFacebookThenUpdateOtherUser()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = facebookParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.Null(e);
            user          = new NCMBUser();
            user.ObjectId = "anotherObjectId";
            user.UserName = "******";
            user.SaveAsync((NCMBException e2) => {
                Assert.Null(e2);
                NCMBTestSettings.CallbackFlag = true;
            });
        });
        yield return(NCMBTestSettings.AwaitAsync());

        user = NCMBUser.CurrentUser;
        Assert.AreEqual("dummyObjectId", user.ObjectId);

        // facebookパラメータ確認
        Dictionary <string, object> authData = user.GetAuthDataForProvider("facebook");

        Assert.AreEqual("facebookDummyId", authData ["id"]);
        Assert.AreEqual("facebookDummyAccessToken", authData ["access_token"]);
        Assert.AreEqual("2017-02-07T01:02:03.004Z", authData ["expiration_date"]);

        // 登録成功の確認
        Assert.IsNotEmpty(NCMBUser._getCurrentSessionToken());
        Assert.True(user.IsLinkWith("facebook"));
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
コード例 #3
0
    public IEnumerator LoginLogoutUpdateUser()
    {
        // テストデータ作成
        NCMBUser.LogInAsync("tarou", "tarou", (e1) =>
        {
            Assert.Null(e1);
            NCMBTestSettings.CallbackFlag = true;
            NCMBUser.LogOutAsync();
            NCMBUser.LogInAsync("tarou", "tarou", (e2) =>
            {
                Assert.Null(e2);
                NCMBUser user = new NCMBUser();
                user.ObjectId = "anotherObjectId";
                user.UserName = "******";
                user.SaveAsync((NCMBException e3) =>
                {
                    Assert.Null(e3);

                    NCMBTestSettings.CallbackFlag = true;
                });
            });
        });

        yield return(NCMBTestSettings.AwaitAsync());

        Assert.True(NCMBTestSettings.CallbackFlag);
        Assert.AreEqual("dummySessionToken", NCMBUser._getCurrentSessionToken());
        Assert.AreEqual("tarou", NCMBUser.CurrentUser.UserName);
    }
コード例 #4
0
    public IEnumerator UpdateOtherUserAfterLogin()
    {
        // テストデータ作成
        NCMBUser.LogInAsync("tarou", "tarou", (e) =>
        {
            Assert.Null(e);

            NCMBUser user = new NCMBUser();
            user.ObjectId = "anotherObjectId";
            user.UserName = "******";
            user.SaveAsync((NCMBException ex) =>
            {
                Assert.Null(ex);

                NCMBTestSettings.CallbackFlag = true;
            });
        });

        yield return(NCMBTestSettings.AwaitAsync());

        // 登録成功の確認
        Assert.True(NCMBTestSettings.CallbackFlag);
        Assert.IsNotNull(NCMBUser.CurrentUser);
        Assert.AreEqual("tarou", NCMBUser.CurrentUser.UserName);
        Assert.AreEqual("dummySessionToken", NCMBUser._getCurrentSessionToken());
    }
コード例 #5
0
    IEnumerator GetID(NCMBObject a, NCMBUser user)
    {
        while (a.ObjectId == null)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        //成功時の処理
        user["LendUmbrellaID"] = a.ObjectId;
        Debug.Log(a.ObjectId);
        user.SaveAsync();

        Texture2D qr = CreateQR(a.ObjectId, 256, 256);

        image.GetComponent <Image>().sprite = Sprite.Create(qr, new Rect(0, 0, qr.width, qr.height), Vector2.zero);
        image.SetActive(true);

        buttonText.text = "閉じる";
        button.onClick.AddListener(Back);
    }
コード例 #6
0
    public IEnumerator UpdateUserNotLoginYet()
    {
        NCMBUser.LogOutAsync((NCMBException e) => {
            Assert.Null(e);
            Assert.Null(NCMBUser.CurrentUser);
            NCMBUser user = new NCMBUser();
            user.ObjectId = "anotherObjectId";
            user.UserName = "******";
            user.SaveAsync((NCMBException e1) =>
            {
                Assert.Null(e1);
                NCMBTestSettings.CallbackFlag = true;
            });
        });

        yield return(NCMBTestSettings.AwaitAsync());

        Assert.True(NCMBTestSettings.CallbackFlag);
        Assert.Null(NCMBUser.CurrentUser);
    }
コード例 #7
0
    public IEnumerator LogInWithAuthDataAsyncTwitterThenUpdateOtherUser()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = twitterParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.Null(e);
            user          = new NCMBUser();
            user.ObjectId = "anotherObjectId";
            user.UserName = "******";
            user.SaveAsync((NCMBException e2) => {
                Assert.Null(e2);
                Assert.AreEqual("newUserName", user.UserName);

                NCMBTestSettings.CallbackFlag = true;
            });
        });
        yield return(NCMBTestSettings.AwaitAsync());

        user = NCMBUser.CurrentUser;
        Assert.AreEqual("dummyObjectId", user.ObjectId);

        // twitterパラメータ確認
        Dictionary <string, object> authData = user.GetAuthDataForProvider("twitter");

        Assert.AreEqual("twitterDummyId", authData ["id"]);
        Assert.AreEqual("twitterDummyScreenName", authData ["screen_name"]);
        Assert.AreEqual("twitterDummyConsumerKey", authData ["oauth_consumer_key"]);
        Assert.AreEqual("twitterDummyConsumerSecret", authData ["consumer_secret"]);
        Assert.AreEqual("twitterDummyAuthToken", authData ["oauth_token"]);
        Assert.AreEqual("twitterDummyAuthSecret", authData ["oauth_token_secret"]);

        // 登録成功の確認
        Assert.NotNull(NCMBUser._getCurrentSessionToken());
        Assert.True(user.IsLinkWith("twitter"));
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
コード例 #8
0
    /// <summary>
    /// ユーザー情報を更新する
    /// (パスワードは NCMB の仕様で更新できない)
    /// </summary>
    /// <param name="email"></param>
    /// <param name="customData"></param>
    void UpdateUserInfo(string email, string customData)
    {
        NCMBUser user = NCMBUser.CurrentUser;

        if (user == null)
        {
            Debug.LogWarning("Not logged in. Log in first.");
            return;
        }

        if (email != "")
        {
            user.Email = email;
        }

        // カスタムデータはキーがない可能性があるため、キーがある場合はデータを更新し、キーがない場合はキーとデータのペアを追加する
        if (user.ContainsKey(m_customDataKey))
        {
            user[m_customDataKey] = customData;
        }
        else
        {
            Debug.LogFormat("Key [{0}] is not found. Add key...", m_customDataKey);
            user.Add(m_customDataKey, customData);
        }

        user.SaveAsync((NCMBException e) =>
        {
            if (e != null)
            {
                Debug.LogError("Failed to save: " + e.ErrorMessage);
            }
            else
            {
                Debug.Log("Saved successfully.");
            }
        });
    }
コード例 #9
0
    private void LoginCallback(ILoginResult result)
    {
        if (FB.IsLoggedIn)
        {
            // facebook ログインの情報を使って NCMB にログインする
            var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
            NCMBFacebookParameters parameters = new NCMBFacebookParameters(aToken.UserId, aToken.TokenString, aToken.ExpirationTime);
            NCMBUser user = new NCMBUser();
            user.AuthData = parameters.param;

            user.LogInWithAuthDataAsync((NCMBException e) =>
            {
                if (e != null)
                {
                    Debug.LogError("Failed to login: "******"Failed to fetch: " + ex.ErrorMessage);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(user.Email))
                            {
                                Dictionary <string, string> formData = new Dictionary <string, string>()
                                {
                                };
                                FB.API("/me?fields=id,email", HttpMethod.GET, (IGraphResult r) =>
                                {
                                    if (r.Error != null)
                                    {
                                        Debug.Log(r.Error);
                                    }
                                    else
                                    {
                                        Debug.Log(r.ResultDictionary.ToJson());
                                        string email = r.ResultDictionary["email"].ToString();
                                        user.Email   = email;
                                        user.SaveAsync((NCMBException exc) =>
                                        {
                                            if (exc != null)
                                            {
                                                Debug.LogError("Failed to save: " + ex.ErrorMessage);
                                            }
                                            else
                                            {
                                                Debug.Log("Saved email data successfully.");
                                            }
                                        });
                                    }
                                }
                                       , formData);
                            }
                        }
                    });
                }
            });
        }
        else
        {
            Debug.Log("User cancelled login");
        }
    }