/// <summary>
 /// 非同期処理でメールアドレスとパスワードを指定して、ユーザのログインを行います。
 /// </summary>
 /// <returns>ログインしたユーザオブジェクト</returns>
 public static IObservable <NCMBUser> LogInWithMailAddressAsync(string email, string password)
 {
     return(Observable.Create <NCMBUser>(observer =>
     {
         var gate = new object();
         var isDisposed = false;
         NCMBUser.LogInWithMailAddressAsync(email, password, error =>
         {
             lock (gate)
             {
                 if (isDisposed)
                 {
                     return;
                 }
                 if (error == null)
                 {
                     observer.OnNext(NCMBUser.CurrentUser);
                     observer.OnCompleted();
                 }
                 else
                 {
                     observer.OnError(error);
                 }
             }
         });
         return Disposable.Create(() =>
         {
             lock (gate)
             {
                 isDisposed = true;
             }
         });
     }));
 }
 public void LoginOrSignUp()
 {
     if (user.text.Length > 0 && password.text.Length > 0)
     {
         if (IsEmail(user.text))
         {
             NCMBUser.LogInWithMailAddressAsync(user.text, password.text, (NCMBException e) => {
                 if (e != null)
                 {
                     if (e.ErrorCode.CompareTo("E400003") == 0)
                     {
                         SignUp();
                     }
                     else
                     {
                         Debug.Log("ログインに失敗: " + e.ErrorMessage);
                     }
                 }
                 else
                 {
                     isLogedIn = true;
                     Debug.Log("ログインに成功!");
                 }
                 SetActive();
             });
         }
         else
         {
             // ユーザー名とパスワードでログイン
             NCMBUser.LogInAsync(user.text, password.text, (NCMBException e) => {
                 if (e != null)
                 {
                     if (e.ErrorCode.CompareTo("E400003") == 0)
                     {
                         SignUp();
                     }
                     else
                     {
                         Debug.Log("ログインに失敗: " + e.ErrorMessage);
                     }
                 }
                 else
                 {
                     isLogedIn = true;
                     Debug.Log("ログインに成功!");
                 }
                 SetActive();
             });
         }
     }
 }
예제 #3
0
    public IEnumerator LogInWithMailAddressAsync()
    {
        // テストデータ作成
        NCMBUser.LogInWithMailAddressAsync("*****@*****.**", "password", (e) => {
            Assert.Null(e);
            NCMBTestSettings.CallbackFlag = true;
        });

        yield return(NCMBTestSettings.AwaitAsync());

        // 登録成功の確認
        Assert.AreEqual("dummySessionToken", NCMBUser._getCurrentSessionToken());
        Assert.AreEqual("*****@*****.**", NCMBUser.CurrentUser.Email);
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
예제 #4
0
    public void Login()
    {
        Debug.Log(Mail.text);
        Debug.Log(Pass.text);
        NCMBUser.LogInWithMailAddressAsync(Mail.text, Pass.text, (NCMBException e) => {
            if (e != null)
            {
                Notification.OpenNotification();
                UnityEngine.Debug.Log("ログインに失敗: " + e.ErrorMessage);
            }
            else
            {
                NCMBUser current = NCMBUser.CurrentUser;
                Userquery.WhereEqualTo("UserID", current.ObjectId);
                Userquery.FindAsync((List <NCMBObject> objList, NCMBException e_userdata) => {
                    if (e_userdata != null)
                    {
                        //検索失敗時の処理
                    }
                    else
                    {
                        if (objList.Count == 0)
                        {
                            UserDataStore.Add("MailAd", Mail.text);
                            UserDataStore.Add("Pass", Pass.text);
                            UserDataStore.Add("UserID", current.ObjectId);
                            UserDataStore.SaveAsync();
                            PlayerPrefs.SetString("MailAd", Mail.text);
                            PlayerPrefs.SetString("Pass", Pass.text);
                        }
                        else
                        {
                            NCMBObject UserData = objList[0];
                            PlayerPrefs.SetString("MailAd", (string)UserData["MailAd"]);
                            PlayerPrefs.SetString("Pass", (string)UserData["Pass"]);
                        }
                    }
                });
                NCMBQuery <NCMBObject> BookMark = new NCMBQuery <NCMBObject> ("BookMark");

                BookMark.WhereEqualTo("UserID", NCMBUser.CurrentUser.ObjectId);
                BookMark.FindAsync((List <NCMBObject> objList, NCMBException er) => {
                    if (e != null)
                    {
                        //検索失敗時の処理
                        Debug.Log("bookmarkError");
                    }
                    else
                    {
                        if (objList.Count == 0)
                        {
                            Debug.Log("Unbookmarked");
                            NCMBObject bookobj = new NCMBObject("BookMark");
                            bookobj.Add("UserID", NCMBUser.CurrentUser.ObjectId);
                            List <string> List = new List <string>();
                            bookobj.Add("Bookmarks", List);
                            bookobj.SaveAsync();
                            return;
                        }
                    }
                });
                UnityEngine.Debug.Log("ログインに成功!");
                //   testvoiddata();
                LoadingScene.LoadNextScene("selection");
                //   SceneManager.LoadScene("selection");
            }
        });
    }