コード例 #1
0
    //
    //登陆按钮
    //
    void OnClickLoginButton()
    {
        var userName = Username_L.text;
        var pwd      = Password_L.text;

        AVUser.LogInAsync(userName, pwd).ContinueWith(t =>
        {
            if (t.IsFaulted || t.IsCanceled)
            {
                MainThreadDispatcher.Send(_ =>
                {
                    var error    = t.Exception.Message; // 登录失败,可以查看错误信息。
                    InfText.text = error;
                    Inf.SetActive(true);
                }, null);
            }
            else
            {
                MainThreadDispatcher.Send(_ =>
                {
                    //登录成功
                    InfText.text = "登陆成功!";
                    Inf.SetActive(true);
                }, null);
            }
        });
        LoginPanel.SetActive(false);
        Username_L.text = "";
        Password_L.text = "";
        _nowUser        = AVUser.CurrentUser;
        _nowUsername    = _nowUser.Username;

        Users.text = "当前用户:" + _nowUsername;
    }
コード例 #2
0
ファイル: Utils.cs プロジェクト: wujun4code/Parse-SDK-dotNET
        public static Task<AVUser> SignUp(string pwd)
        {
            var u = Utils.RandomUsername();

            AVUser user = new AVUser()
            {
                Username = u,
                Password = pwd,
                MobilePhoneNumber = GetRandomTel()
            };

            return user.SignUpAsync().ContinueWith(t =>
            {
                return user;
            });
        }
コード例 #3
0
        public Task TestExistsAsync()
        {
            var storageController = new Mock<IStorageController>();
              var mockedStorage = new Mock<IStorageDictionary<string, object>>();
              var controller = new AVCurrentUserController(storageController.Object);
              var user = new AVUser();

              storageController.Setup(c => c.LoadAsync()).Returns(Task.FromResult(mockedStorage.Object));

              bool contains = false;
              mockedStorage.Setup(s => s.AddAsync("CurrentUser", It.IsAny<object>())).Callback(() => {
            contains = true;
              }).Returns(Task.FromResult<object>(null)).Verifiable();

              mockedStorage.Setup(s => s.RemoveAsync("CurrentUser")).Callback(() => {
            contains = false;
              }).Returns(Task.FromResult<object>(null)).Verifiable();

              mockedStorage.Setup(s => s.ContainsKey("CurrentUser")).Returns(() => contains);

              return controller.SetAsync(user, CancellationToken.None).OnSuccess(_ => {
            Assert.AreEqual(user, controller.CurrentUser);

            return controller.ExistsAsync(CancellationToken.None);
              }).Unwrap()
              .OnSuccess(t => {
            Assert.IsTrue(t.Result);

            controller.ClearFromMemory();
            return controller.ExistsAsync(CancellationToken.None);
              }).Unwrap()
              .OnSuccess(t => {
            Assert.IsTrue(t.Result);

            controller.ClearFromDisk();
            return controller.ExistsAsync(CancellationToken.None);
              }).Unwrap()
              .OnSuccess(t => {
            Assert.IsFalse(t.Result);
            mockedStorage.Verify();
              });
        }
コード例 #4
0
ファイル: AVUser.cs プロジェクト: wujun4code/Parse-SDK-dotNET
 private static Task SaveCurrentUserAsync(AVUser user, CancellationToken cancellationToken)
 {
     return CurrentUserController.SetAsync(user, cancellationToken);
 }
コード例 #5
0
ファイル: AVUser.cs プロジェクト: wujun4code/Parse-SDK-dotNET
 private static Task SaveCurrentUserAsync(AVUser user)
 {
     return SaveCurrentUserAsync(user, CancellationToken.None);
 }
コード例 #6
0
        public Task TestSignUp()
        {
            var u = Utils.RandomUsername();
            var p = Utils.RandomString(10);
            AVUser user = new AVUser()
            {
                Username = u,
                Password = p
            };

            return user.SignUpAsync().ContinueWith(t =>
            {
                Assert.False(t.IsFaulted);
                Assert.False(t.IsCanceled);
                Assert.AreEqual(u, user.Username);
                Assert.False(user.GetState().ContainsKey("password"));
                Assert.IsNotNull(user.ObjectId);
            });
        }
コード例 #7
0
        public void TestImmutableKeys()
        {
            AVUser user = new AVUser();
            string[] immutableKeys = new string[] { "sessionToken", "isNew" };

            foreach (var key in immutableKeys)
            {
                Assert.Throws<InvalidOperationException>(() =>
                  user[key] = "1234567890"
                );

                Assert.Throws<InvalidOperationException>(() =>
                  user.Add(key, "1234567890")
                );

                Assert.Throws<InvalidOperationException>(() =>
                  user.AddRangeUniqueToList(key, new string[] { "1234567890" })
                );

                Assert.Throws<InvalidOperationException>(() =>
                  user.Remove(key)
                );

                Assert.Throws<InvalidOperationException>(() =>
                  user.RemoveAllFromList(key, new string[] { "1234567890" })
                );
            }

            // Other special keys should be good
            user["username"] = "******";
            user["password"] = "******";
        }
コード例 #8
0
        public Task TestLogOut()
        {
            var storageController = new Mock<IStorageController>(MockBehavior.Strict);
              var controller = new AVCurrentUserController(storageController.Object);
              var user = new AVUser();

              return controller.SetAsync(user, CancellationToken.None).OnSuccess(_ => {
            Assert.AreEqual(user, controller.CurrentUser);
            return controller.ExistsAsync(CancellationToken.None);
              }).Unwrap()
              .OnSuccess(t => {
            Assert.IsTrue(t.Result);

            return controller.LogOutAsync(CancellationToken.None);
              }).Unwrap().OnSuccess(_ => controller.GetAsync(CancellationToken.None)).Unwrap()
              .OnSuccess(t => {
            Assert.IsNull(t.Result);

            return controller.ExistsAsync(CancellationToken.None);
              }).Unwrap()
              .OnSuccess(t => {
            Assert.IsFalse(t.Result);
              });
        }
コード例 #9
0
        public Task TestGetSetAsync()
        {
            var storageController = new Mock<IStorageController>(MockBehavior.Strict);
              var mockedStorage = new Mock<IStorageDictionary<string, object>>();
              var controller = new AVCurrentUserController(storageController.Object);
              var user = new AVUser();

              storageController.Setup(s => s.LoadAsync()).Returns(Task.FromResult(mockedStorage.Object));

              return controller.SetAsync(user, CancellationToken.None).OnSuccess(_ => {
            Assert.AreEqual(user, controller.CurrentUser);

            object jsonObject = null;
            Predicate<object> predicate = o => {
              jsonObject = o;
              return true;
            };

            mockedStorage.Verify(s => s.AddAsync("CurrentUser", Match.Create<object>(predicate)));
            mockedStorage.Setup(s => s.TryGetValue("CurrentUser", out jsonObject)).Returns(true);

            return controller.GetAsync(CancellationToken.None);
              }).Unwrap()
              .OnSuccess(t => {
            Assert.AreEqual(user, controller.CurrentUser);

            controller.ClearFromMemory();
            Assert.AreNotEqual(user, controller.CurrentUser);

            return controller.GetAsync(CancellationToken.None);
              }).Unwrap()
              .OnSuccess(t => {
            Assert.AreNotSame(user, controller.CurrentUser);
            Assert.IsNotNull(controller.CurrentUser);
              });
        }
コード例 #10
0
        public Task TestIsCurrent()
        {
            var storageController = new Mock<IStorageController>(MockBehavior.Strict);
              var mockedStorage = new Mock<IStorageDictionary<string, object>>();
              var controller = new AVCurrentUserController(storageController.Object);
              var user = new AVUser();
              var user2 = new AVUser();

              storageController.Setup(s => s.LoadAsync()).Returns(Task.FromResult(mockedStorage.Object));

              return controller.SetAsync(user, CancellationToken.None).OnSuccess(t => {
            Assert.IsTrue(controller.IsCurrent(user));
            Assert.IsFalse(controller.IsCurrent(user2));

            controller.ClearFromMemory();

            Assert.IsFalse(controller.IsCurrent(user));

            return controller.SetAsync(user, CancellationToken.None);
              }).Unwrap()
              .OnSuccess(t => {
            Assert.IsTrue(controller.IsCurrent(user));
            Assert.IsFalse(controller.IsCurrent(user2));

            controller.ClearFromDisk();

            Assert.IsFalse(controller.IsCurrent(user));

            return controller.SetAsync(user2, CancellationToken.None);
              }).Unwrap()
              .OnSuccess(t => {
            Assert.IsFalse(controller.IsCurrent(user));
            Assert.IsTrue(controller.IsCurrent(user2));
              });
        }
コード例 #11
0
ファイル: AVACL.cs プロジェクト: aisk/LeanCloud-SDK-dotNET
 /// <summary>
 /// Sets whether the given user is allowed to read this object.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="allowed">Whether the user has permission.</param>
 public void SetReadAccess(AVUser user, bool allowed)
 {
     SetReadAccess(user.ObjectId, allowed);
 }
コード例 #12
0
ファイル: AVACL.cs プロジェクト: wujun4code/Parse-SDK-dotNET
 /// <summary>
 /// Creates an ACL where only the provided user has access.
 /// </summary>
 /// <param name="owner">The only user that can read or write objects governed by this ACL.</param>
 public AVACL(AVUser owner)
 {
     SetReadAccess(owner, true);
       SetWriteAccess(owner, true);
 }
コード例 #13
0
ファイル: AVACL.cs プロジェクト: wujun4code/Parse-SDK-dotNET
 /// <summary>
 /// Sets whether the given user is allowed to write this object.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="allowed">Whether the user has permission.</param>
 public void SetWriteAccess(AVUser user, bool allowed)
 {
     SetWriteAccess(user.ObjectId, allowed);
 }
コード例 #14
0
ファイル: AVACL.cs プロジェクト: wujun4code/Parse-SDK-dotNET
 /// <summary>
 /// Gets whether the given user is *explicitly* allowed to write this object.
 /// Even if this returns false, the user may still be able to write it if
 /// PublicReadAccess is true or a role that the user belongs to has write access.
 /// </summary>
 /// <param name="user">The user to check.</param>
 /// <returns>Whether the user has access.</returns>
 public bool GetWriteAccess(AVUser user)
 {
     return GetWriteAccess(user.ObjectId);
 }
コード例 #15
0
ファイル: AVACL.cs プロジェクト: wujun4code/Parse-SDK-dotNET
 /// <summary>
 /// Gets whether the given user is *explicitly* allowed to read this object.
 /// Even if this returns false, the user may still be able to read it if
 /// PublicReadAccess is true or a role that the user belongs to has read access.
 /// </summary>
 /// <param name="user">The user to check.</param>
 /// <returns>Whether the user has access.</returns>
 public bool GetReadAccess(AVUser user)
 {
     return GetReadAccess(user.ObjectId);
 }