Пример #1
0
	void Start(){
		count = 0;
		if(Kii.AppId != null)
			user = KiiUser.CurrentUser;

		//Set up push listeners
		KiiPushPlugin kiiPushPlugin = GameObject.Find ("KiiPushPlugin").GetComponent<KiiPushPlugin> ();
		Debug.Log ("Found KiiPushPlugin object in game objects");
		kiiPushPlugin.OnPushMessageReceived += (ReceivedMessage message) => {
			// This event handler is called when received the push message.
			switch (message.PushMessageType)
			{
			case ReceivedMessage.MessageType.PUSH_TO_APP:
				Debug.Log ("#####PUSH_TO_APP Message");
				// do something to notify your app of the incomig message
				break;
			case ReceivedMessage.MessageType.PUSH_TO_USER:
				Debug.Log ("#####PUSH_TO_USER Message");
				// your user received a message, do something
				break;
			case ReceivedMessage.MessageType.DIRECT_PUSH:
				Debug.Log ("#####DIRECT_PUSH Message");
				// A direct push message was sent from developer.kii.com
				// Let's grab the url value of the message and open that page
				string url = message.GetString("url");
				Debug.Log ("Url in message is: " + url);
				Application.OpenURL("http://" + url);
				break;
			}
			Debug.Log("Type=" + message.PushMessageType);
			Debug.Log("Sender=" + message.Sender);
			Debug.Log("Scope=" + message.ObjectScope);
			// You can get the value of custom field using GetXXXX method.
			Debug.Log("Payload=" + message.GetString("payload"));
		};

		#if UNITY_IPHONE
		KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS;
		#elif UNITY_ANDROID
		KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID;
		#else
		KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID;
		#endif

		kiiPushPlugin.RegisterPush((string pushToken, Exception e0)=> {
			if (e0 != null) {
				Debug.Log("#####failed to RegisterPush");
				return;
			}
			Debug.Log ("#####RegistrationId=" + pushToken);
			Debug.Log ("#####Install");
			KiiUser.PushInstallation (true).Install (pushToken, deviceType, (Exception e3)=>{
				if (e3 != null)
				{
					Debug.Log ("#####failed to Install");
					return;
				}
			});
		});
	}
Пример #2
0
 void Awake()
 {
     username = GameObject.Find("Username").GetComponent<InputField>();
     password = GameObject.Find("Password").GetComponent<InputField>();
     error = GameObject.Find ("Error").GetComponent<Text>();
     loggedIn = false;
     User = null;
     setErrText = "";
     Kii.Initialize(appId, appKey, Kii.Site.US);
 }
Пример #3
0
    void LoginCallback(KiiUser callbackUser, System.Exception exc)
    {
        if (exc != null && exc as System.NullReferenceException == null) {
            // Error handling
            setErrText = "LOGIN FAILURE: " + exc.Message;
            return;
        }
        setErrText = "LOGIN SUCCESS " + callbackUser.Username;

        User = callbackUser;
        loggedIn = true;
    }
Пример #4
0
	private void register () {
		user = null;
		OnCallback = true;
		KiiUser built_user = KiiUser.BuilderWithName(username).Build();
		built_user.Register(password, (KiiUser user2, Exception e) => {
			if (e == null)
			{
				#if UNITY_IPHONE
				bool development = true;      // choose development/production for iOS
				string USER = username;
				string PASS = password;
				KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS;
				plugin = GameObject.Find("KiiPush").GetComponent<KiiPushPlugin>();
				plugin.RegisterPush((string pushToken, Exception e0) => {
					Debug.Log("Token :"+pushToken);
					if( e0 == null ){
						KiiUser.LogIn(USER, PASS, (KiiUser kiiuser, Exception e1) => {
							if( e1 == null ){
								KiiUser.PushInstallation(development).Install(pushToken, deviceType, (Exception e2) => {
									Debug.Log ("Push registration completed");
									KiiUser user3 = KiiUser.CurrentUser;
									KiiBucket bucket = Kii.Bucket("FlappyDogHighScore");
									KiiPushSubscription ps = user3.PushSubscription;
		 							ps.Subscribe(bucket, (KiiSubscribable target, Exception e3) => {
										if (e3 != null)
										{
											// check fail cause
											Debug.Log("Subscription Failed");
											Debug.Log(e3.ToString());
										}
									}); 
								});
							}else{
								Debug.Log("e1 error: "+e1.ToString());
							}; 
						});
					}else{
						Debug.Log("e0 error: "+e0.ToString());
					};
				});
				#endif

				user = user2;
				Debug.Log ("Register completed");
			} else {
				user = null;
				OnCallback = false;
				Debug.Log ("Register failed : " + e.ToString());
			}
		});
	}
Пример #5
0
	private void Login () {
		user = null;
		OnCallback = true;
		KiiUser.LogIn(username, password, (KiiUser user2, Exception e) => {
			if (e == null) {
				Debug.Log ("Login completed");
				user = user2;
			} else {
				user = null;
				OnCallback = false;
				Debug.Log ("Login failed : " + e.ToString());
			}
		});
	}
Пример #6
0
    void PerformRemoveUser(KiiUser user)
    {
        message       = "Removing user...";
        ButtonEnabled = false;

        currentGroup.RemoveUser(user);
        currentGroup.Save((KiiGroup group, Exception e) =>
        {
            ButtonEnabled = true;
            if (e != null)
            {
                message = "Failed to remove user " + e.ToString();
                return;
            }
            message = "Remove user succeeded";
        });
    }
Пример #7
0
        public void Test_SetGlobalPhone()
        {
            string identifier = "kii1234";
            string phone      = "+8719011112222";

            KiiUser.Builder builder = KiiUser.BuilderWithIdentifier(identifier);
            builder.SetGlobalPhone(phone);

            builder.Build().Register("123456");

            KiiUser user = KiiUser.CurrentUser;

            Assert.AreEqual(identifier, user.Username);
            Assert.IsNull(user.Email);
            Assert.AreEqual(phone, user.Phone);
            Assert.IsNull(user.Country);
        }
        public void PhoneVerificationTest()
        {
            // Register user with phone number
            string  username = "******" + CurrentTimeMillis();
            string  phone    = GenerateGlobalPhoneNumber();
            KiiUser user     = KiiUser.BuilderWithPhone(phone).SetName(username).Build();

            user.Register("password");
            Assert.AreEqual(phone, user.Phone);
            Assert.IsFalse(user.PhoneVerified);
            Assert.IsNull(user.PendingPhone);

            // verify Phone by admin
            verifyPhone(user.ID, user.Phone);

            // Check the user
            user.Refresh();
            Assert.AreEqual(phone, user.Phone);
            Assert.IsTrue(user.PhoneVerified);
            Assert.IsNull(user.PendingPhone);

            // Change phone number
            string newPhone = GenerateGlobalPhoneNumber();

            KiiUser.ChangePhone(newPhone);

            Assert.AreEqual(phone, KiiUser.CurrentUser.Phone);
            Assert.IsTrue(KiiUser.CurrentUser.PhoneVerified);
            Assert.IsNull(KiiUser.CurrentUser.PendingPhone);

            // Check the user
            user.Refresh();
            Assert.AreEqual(phone, user.Phone);
            Assert.IsTrue(user.PhoneVerified);
            Assert.AreEqual(newPhone, user.PendingPhone);

            // verify Phone by admin
            verifyPhone(user.ID, user.PendingPhone);

            // Check the user
            user.Refresh();
            Assert.AreEqual(newPhone, user.Phone);
            Assert.IsTrue(user.PhoneVerified);
            Assert.IsNull(user.PendingPhone);
        }
        public void EmailVerificationTest()
        {
            // Register user with email
            string  username = "******" + CurrentTimeMillis();
            string  email    = username + "@kii.com";
            KiiUser user     = KiiUser.BuilderWithEmail(email).SetName(username).Build();

            user.Register("password");
            Assert.AreEqual(email, user.Email);
            Assert.IsFalse(user.EmailVerified);
            Assert.IsNull(user.PendingEmail);

            // verify Email by admin
            verifyEmail(user.ID, user.Email);

            // Check the user
            user.Refresh();
            Assert.AreEqual(email, user.Email);
            Assert.IsTrue(user.EmailVerified);
            Assert.IsNull(user.PendingEmail);

            // Change Email
            string newEmail = "new_" + email;

            KiiUser.ChangeEmail(newEmail);

            Assert.AreEqual(email, KiiUser.CurrentUser.Email);
            Assert.IsTrue(KiiUser.CurrentUser.EmailVerified);
            Assert.IsNull(KiiUser.CurrentUser.PendingEmail);

            // Check the user
            user.Refresh();
            Assert.AreEqual(email, user.Email);
            Assert.IsTrue(user.EmailVerified);
            Assert.AreEqual(newEmail, user.PendingEmail);

            // verify Email by admin
            verifyEmail(user.ID, user.PendingEmail);

            // Check the user
            user.Refresh();
            Assert.AreEqual(newEmail, user.Email);
            Assert.IsTrue(user.EmailVerified);
            Assert.IsNull(user.PendingEmail);
        }
Пример #10
0
        private void CheckEntriesAfterAdd(KiiUser user, IList <KiiACLEntry <KiiBucket, BucketAction> > list)
        {
            Assert.AreEqual(5, list.Count);
            int count1 = 0;
            int count2 = 0;
            int count3 = 0;
            int count4 = 0;

            foreach (KiiACLEntry <KiiBucket, BucketAction> ent in list)
            {
                switch (ent.Action)
                {
                case BucketAction.CREATE_OBJECTS_IN_BUCKET:
                    ++count1;
                    Assert.AreEqual(user.ID, ((KiiUser)ent.Subject).ID);
                    break;

                case BucketAction.DROP_BUCKET_WITH_ALL_CONTENT:
                    ++count2;
                    Assert.AreEqual(user.ID, ((KiiUser)ent.Subject).ID);
                    break;

                case BucketAction.QUERY_OBJECTS_IN_BUCKET:
                    ++count3;
                    Assert.AreEqual(user.ID, ((KiiUser)ent.Subject).ID);
                    break;

                case BucketAction.READ_OBJECTS_IN_BUCKET:
                    ++count4;
                    if (ent.Subject is KiiUser)
                    {
                        Assert.AreEqual(user.ID, ((KiiUser)ent.Subject).ID);
                    }
                    else
                    {
                        Assert.IsTrue(ent.Subject is KiiAnyAuthenticatedUser);
                    }
                    break;
                }
            }
            Assert.AreEqual(1, count1);
            Assert.AreEqual(1, count2);
            Assert.AreEqual(1, count3);
            Assert.AreEqual(2, count4);
        }
Пример #11
0
 public void register()
 {
     //Espacio para que el usuario se registre
     userName = nameregister.value;
     pwd      = passregister.value;
     emailId  = mailregister.value;
     if (userName == "" || pwd == "" || emailId == "")
     {
         faltan.text = "One or more required field(s) are missing.";
     }
     else
     {
         /*userService = sp.BuildUserService ();
          * userService.CreateUser (userName, pwd, emailId, callBackUser);
          * cLabel.SetActive (true);
          * Debug.Log ("El Usuario ha sido creado.");
          * mystats.idplayer = userName;
          * Dictionary <string, object> jsonDoc = new Dictionary <string,object> ();
          * storageService = sp.BuildStorageService ();
          * storageService.FindDocumentById (dbName, collectionName, jsonid, callBack);
          * storageService.InsertJSONDocument(dbName, mystats.idplayer + "myDataBase", json, callBack1);
          */
         mystats.idplayer = userName;
         KiiUser.Builder builder = KiiUser.BuilderWithName(userName);
         builder.WithEmail(emailId);
         KiiUser usr = builder.Build();
         usr.Register(pwd, (KiiUser user, Exception e) =>
         {
             if (e != null)
             {
                 faltan.text = "Password must be between 4 to 50 alphanumeric characters.";
                 Debug.LogError("Signup failed: " + e.ToString());
                 // process error
             }
             else
             {
                 Debug.Log("Signup succeeded.");
                 faltan.text = "Signup succeeded. Signing in...";
                 Save();
                 Application.LoadLevel("PruebaMatchList");
                 // do something with user, it's a valid user now
             }
         });
     }
 }
Пример #12
0
        public void Test_ResetPassword()
        {
            ArrayList errors = new ArrayList();

            for (int i = 0; i < TESTCASES.Length; i++)
            {
                TestCase tc = TESTCASES [i];
                if (tc.ExpectedResult)
                {
                    KiiUser.ResetPassword(tc.Identifier, (Exception e) => {
                        if (e != null)
                        {
                            errors.Add("TestCase : " + i + " identifier : "
                                       + tc.Identifier + " message :" + e.Message);
                        }
                    });
                }
                else
                {
                    KiiUser.ResetPassword(tc.Identifier, (Exception e) => {
                        if (e == null)
                        {
                            // error if exception is not thrown.
                            errors.Add("TestCase : " + i + " identifier : "
                                       + tc.Identifier);
                        }
                        else if (!e.GetType().IsAssignableFrom(typeof(ArgumentException)))
                        {
                            errors.Add("TestCase : " + i + " identifier : "
                                       + tc.Identifier + " message :" + e.Message);
                        }
                    });
                }
            }
            if (errors.Count > 0)
            {
                StringBuilder builder = new StringBuilder(
                    "One or more case failed. Messages : \n");
                foreach (String msg in errors)
                {
                    builder.Append(msg + "\n");
                }
                Assert.Fail(builder.ToString());
            }
        }
Пример #13
0
        public void Test_SetName()
        {
            string identifier = "*****@*****.**";
            string username   = "******";

            KiiUser.Builder builder = KiiUser.BuilderWithIdentifier(identifier);

            builder.SetName(username);

            builder.Build().Register("123456");

            KiiUser user = KiiUser.CurrentUser;

            Assert.AreEqual(username, user.Username);
            Assert.AreEqual(identifier, user.Email);
            Assert.IsNull(user.Phone);
            Assert.IsNull(user.Country);
        }
        public void Test_0101_ChangeEmail_already_exists()
        {
            this.LogIn();

            string newEmail = "*****@*****.**";

            // set Response
            client.AddResponse(new CloudException(409,
                                                  "{" +
                                                  "\"errorCode\" : \"USER_ALREADY_EXISTS\"," +
                                                  "\"message\" : \"User with emailAddress [email protected] already exists\"," +
                                                  "\"value\" : \"[email protected]\"," +
                                                  "\"field\" : \"emailAddress\"," +
                                                  "\"suppressed\" : [ ]" +
                                                  "}"));

            KiiUser.ChangeEmail(newEmail);
        }
        public void Test_0201_ChangePhone_already_exists()
        {
            this.LogIn();

            string newPhone = "+818011112222";

            // set Response
            client.AddResponse(new CloudException(409,
                                                  "{" +
                                                  "\"errorCode\" : \"USER_ALREADY_EXISTS\"," +
                                                  "\"message\" : \"User with phoneNumber +818011112222 already exists\"," +
                                                  "\"value\" : \"+818011112222\"," +
                                                  "\"field\" : \"phoneNumber\"," +
                                                  "\"suppressed\" : [ ]" +
                                                  "}"));

            KiiUser.ChangePhone(newPhone);
        }
Пример #16
0
        public void Test_SetEmail()
        {
            string identifier = "+8719011112222";
            string email      = "*****@*****.**";

            KiiUser.Builder builder = KiiUser.BuilderWithIdentifier(identifier);

            builder.SetEmail(email);

            builder.Build().Register("123456");

            KiiUser user = KiiUser.CurrentUser;

            Assert.IsNull(user.Username);
            Assert.AreEqual(email, user.Email);
            Assert.AreEqual(identifier, user.Phone);
            Assert.IsNull(user.Country);
        }
Пример #17
0
        public void RegisterAsPseudoUserTest_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);

            KiiUser.RegisterAsPseudoUser(null, (KiiUser user, Exception e) => {
                cd.Signal();
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 10)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(KiiUser.AccessToken);
            Assert.IsNull(KiiUser.CurrentUser.Displayname);
            Assert.IsNull(KiiUser.CurrentUser.Country);
            Assert.IsTrue(KiiUser.AccessToken.Length > 10);
            Assert.IsTrue(KiiUser.CurrentUser.IsPseudoUser);
        }
Пример #18
0
    //KiiCloudへログインする
    public bool loginUser(string userName, string password)
    {
        KiiUser user;

        try
        {
            user = KiiUser.LogIn(userName, password);
            Debug.Log("Success user login : "******"Failed user login : "******" : " + exception);
            user = null;
            return(false);
        }

        return(true);
    }
Пример #19
0
    static public void AutoLogin( )
    {
        string token = PlayerPrefs.GetString("access token");

        LoginUI.instance.Wait();
        KiiUser.LoginWithToken(token, (KiiUser loginedUser, Exception e) =>
        {
            LoginUI.instance.StopWait();
            if (e == null)
            {
                LoginUI.instance.OnLoginSuccess();
            }
            else
            {
                HandlerLoginException(e);
            }
        });
    }
        public void Test_IdentifyIsNull_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);

            client.AddResponse(204, null);
            Exception ex = null;

            KiiUser.ResetPassword(null, KiiUser.NotificationMethod.SMS, (Exception e) => {
                ex = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(ex);
            Assert.IsTrue(ex is ArgumentException);
        }
        private void LogIn()
        {
            // set Response
            client.AddResponse(200, "{" +
                               "\"id\" : \"user1234\"," +
                               "\"access_token\" : \"cdef\"," +
                               "\"expires_in\" : 9223372036854775}");
            KiiUser   loginUser = null;
            Exception exp       = null;

            KiiUser.LogIn("kii1234", "pass1234", (KiiUser u, Exception e) => {
                loginUser = u;
                exp       = e;
            });
            Assert.IsNotNull(loginUser);
            Assert.AreEqual("user1234", loginUser.ID);
            Assert.IsNull(exp);
        }
Пример #22
0
 private void Login()
 {
     user       = null;
     OnCallback = true;
     KiiUser.LogIn(username, password, (KiiUser user2, Exception e) => {
         if (e == null)
         {
             Debug.Log("Login completed");
             user = user2;
         }
         else
         {
             user       = null;
             OnCallback = false;
             Debug.Log("Login failed : " + e.ToString());
         }
     });
 }
Пример #23
0
        public void Test_0100_findByEmail()
        {
            this.LogIn();

            // set Response
            this.SetStandardFindResponse();
            KiiUser   found = null;
            Exception exp   = null;

            KiiUser.FindUserByEmail("*****@*****.**", (KiiUser u, Exception e) => {
                found = u;
                exp   = e;
            });
            Assert.IsNull(exp);
            Assert.AreEqual("a7784f94-3134-4a78-82af-75df87f23873", found.ID);
            Assert.AreEqual("Test003", found.Username);
            Assert.AreEqual("Person Test003", found.Displayname);
        }
Пример #24
0
    void RegisterPush()
    {
#if UNITY_IPHONE
        KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS;
#elif UNITY_ANDROID
        KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID;
#else
        KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID;
#endif

        if (this.kiiPushPlugin == null)
        {
            Debug.Log("#####failed to find KiiPushPlugin");
            return;
        }
        this.kiiPushPlugin.RegisterPush((string pushToken, System.Exception e0) =>
        {
            if (e0 != null)
            {
                Debug.Log("#####failed to RegisterPush: " + pushToken);
                return;
            }

            Debug.Log("#####RegistrationId= Token:" + pushToken);
            Debug.Log("#####Install");

            KiiUser.PushInstallation(false).Install(pushToken, deviceType, (System.Exception e3) =>
            {
                if (e3 != null)
                {
                    Debug.Log("#####failed to Install");
                    this.ShowException("Failed to install PushNotification -- pushToken=" + pushToken, e3);
                    return;
                }

                suscribeTopic("MainTopic");
                String country_topic = PlayerPrefs.GetString("pais_locale");
                if (country_topic != null && country_topic != "")
                {
                    suscribeTopic(country_topic);
                }
            });
        });
    }
Пример #25
0
        public void RegisterGroupWithIDASyncTest()
        {
            string         groupID   = GetGroupID();
            string         groupName = "group-" + DateTime.Now.Ticks.ToString();
            List <KiiUser> members   = new List <KiiUser>();

            members.Add(KiiUser.CreateByUri(new Uri("kiicloud://users/user-member-0001")));
            members.Add(KiiUser.CreateByUri(new Uri("kiicloud://users/user-member-0002")));

            client.AddResponse(200, "{\"groupID\":\"" + groupID + "\"}");

            CountDownLatch cd        = new CountDownLatch(1);
            KiiGroup       group     = null;
            Exception      exception = null;

            KiiGroup.RegisterGroupWithID(groupID, groupName, members, (KiiGroup result, Exception e) => {
                group     = result;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(exception);

            Assert.AreEqual(groupID, group.ID);
            Assert.AreEqual(groupName, group.Name);
            Assert.AreEqual(KiiUser.CurrentUser.ID, group.Owner.ID);

            JsonObject expectedRequestBody = new JsonObject();
            JsonArray  expectedMembers     = new JsonArray();

            expectedMembers.Put("user-member-0001");
            expectedMembers.Put("user-member-0002");
            expectedRequestBody.Put("owner", KiiUser.CurrentUser.ID);
            expectedRequestBody.Put("name", groupName);
            expectedRequestBody.Put("members", expectedMembers);

            Assert.AreEqual(KiiHttpMethod.PUT, client.RequestMethod [0]);
            Assert.AreEqual("https://api.kii.com/api/apps/" + AppID + "/groups/" + groupID, client.RequestUrl [0]);
            KiiAssertion.AssertJson(expectedRequestBody, new JsonObject(client.RequestBody [0]));
            Assert.AreEqual("application/vnd.kii.GroupCreationRequest+json", client.RequestHeader[0]["content-type"]);
        }
        public void Test_CompleteResetPasswordWithoutPinCode_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);
            Exception      ex = null;

            string identifier  = Guid.NewGuid().ToString();
            string newPassword = "******";

            KiiUser.CompleteResetPassword(identifier, null, newPassword, (Exception e) => {
                ex = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(ex);
            Assert.IsTrue(ex is ArgumentException);
        }
        public void Test_BadRequest_Async()
        {
            CountDownLatch cd         = new CountDownLatch(1);
            string         identifier = "400@kii@com";

            client.AddResponse(new BadRequestException("", null, "", BadRequestException.Reason.INVALID_JSON));
            Exception ex = null;

            KiiUser.ResetPassword(identifier, KiiUser.NotificationMethod.SMS, (Exception e) => {
                ex = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(ex);
            Assert.IsTrue(ex is BadRequestException);
        }
        public void KiiTopicAclTest()
        {
            this.LogIn();

            KiiTopic appTopicA  = Kii.Topic("A");
            KiiTopic appTopicA_ = Kii.Topic("A");
            KiiTopic appTopicB  = Kii.Topic("B");
            KiiTopic usrTopicA  = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234")).Topic("A");

            KiiTopicACL acl1 = null;
            KiiTopicACL acl2 = null;

            // same object
            acl1 = new KiiTopicACL(appTopicA);
            acl2 = new KiiTopicACL(appTopicA_);
            Assert.IsTrue(acl1.Equals(acl2));
            Assert.IsTrue(acl1.GetHashCode() == acl2.GetHashCode());
            Assert.IsFalse(acl1 == acl2);
            // same object and action
            acl1 = new KiiTopicACL(appTopicA, TopicAction.SEND_MESSAGE_TO_TOPIC);
            acl2 = new KiiTopicACL(appTopicA_, TopicAction.SEND_MESSAGE_TO_TOPIC);
            Assert.IsTrue(acl1.Equals(acl2));
            Assert.IsTrue(acl1.GetHashCode() == acl2.GetHashCode());
            Assert.IsFalse(acl1 == acl2);
            // different action
            acl1 = new KiiTopicACL(appTopicA, TopicAction.SEND_MESSAGE_TO_TOPIC);
            acl2 = new KiiTopicACL(appTopicA_, TopicAction.SUBSCRIBE_TO_TOPIC);
            Assert.IsFalse(acl1.Equals(acl2));
            Assert.IsFalse(acl1.GetHashCode() == acl2.GetHashCode());
            Assert.IsFalse(acl1 == acl2);
            // different topic name
            acl1 = new KiiTopicACL(appTopicA, TopicAction.SEND_MESSAGE_TO_TOPIC);
            acl2 = new KiiTopicACL(appTopicB, TopicAction.SEND_MESSAGE_TO_TOPIC);
            Assert.IsFalse(acl1.Equals(acl2));
            Assert.IsFalse(acl1.GetHashCode() == acl2.GetHashCode());
            Assert.IsFalse(acl1 == acl2);
            // different scope of bucket
            acl1 = new KiiTopicACL(appTopicA, TopicAction.SEND_MESSAGE_TO_TOPIC);
            acl2 = new KiiTopicACL(usrTopicA, TopicAction.SEND_MESSAGE_TO_TOPIC);
            Assert.IsFalse(acl1.Equals(acl2));
            Assert.IsFalse(acl1.GetHashCode() == acl2.GetHashCode());
            Assert.IsFalse(acl1 == acl2);
        }
        public void Test_0010_Save_update_add()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234"));

            group.AddUser(user);

            // set Response
            client.RequestUrl.Clear();
            this.SetStandardSaveResponse(client);

            group.Save();

            Assert.AreEqual(1, client.RequestUrl.Count);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/groups/group1234/members/user1234", client.RequestUrl[0]);
        }
        public void Test_0001_ChangePassword_wrongPassword()
        {
            this.LogIn();

            string newPassword = "******";
            string oldPassword = "******";

            // set Response
            client.AddResponse(new CloudException(401,
                                                  "{" +
                                                  "\"errorCode\" : \"WRONG_PASSWORD\"," +
                                                  "\"message\" : \"The provided password is wrong\"," +
                                                  "\"appID\" : \"appId\"," +
                                                  "\"userID\" : \"86f3cdcf-950d-4d26-aa1c-443573de1736\"," +
                                                  "\"suppressed\" : [ ]" +
                                                  "}"));

            KiiUser.ChangePassword(newPassword, oldPassword);
        }
Пример #31
0
        public void UpdateTest_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);

            string  unixTime = CurrentTimeMillis().ToString();
            string  username = "******" + unixTime;
            string  email    = username + "@kii.com";
            string  phone    = "+874" + unixTime.Substring(unixTime.Length - 9, 9);
            KiiUser actual   = null;

            KiiUser newUser = KiiUser.BuilderWithName(username).Build();

            newUser["birthday"] = "1978/7/22";
            newUser.Register("123ABC", (KiiUser registeredUser, Exception e1) => {
                IdentityData.Builder builder = IdentityData.Builder.CreateWithEmail(email);
                builder.WithPhone(phone);
                IdentityData identityData = builder.Build();

                UserFields userFields  = new UserFields();
                userFields.Displayname = "disp";
                userFields.Country     = "JP";
                userFields["age"]      = 30;
                userFields.RemoveFromServer("birthday");

                registeredUser.Update(identityData, userFields, (KiiUser updatedUser, Exception e2) => {
                    actual = updatedUser;
                    cd.Signal();
                });
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 10)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsFalse(actual.IsPseudoUser);
            Assert.AreEqual(username, actual.Username);
            Assert.AreEqual(email, actual.Email);
            Assert.AreEqual(phone, actual.Phone);
            Assert.AreEqual("disp", actual.Displayname);
            Assert.AreEqual("JP", actual.Country);
            Assert.IsFalse(actual.Has("birthday"));
            Assert.AreEqual(30, actual.GetInt("age"));
        }
Пример #32
0
        public void Test_0002_Register_With_LocalPhoneNumber()
        {
            string response1 = @"
            {
                 ""userID"" : ""0398e67a-818d-47ee-83fb-3519a6197b81"",
                 ""internalUserID"" : 148478248144076800,
                 ""phoneNumber"": ""09011112222"",
                 ""phoneNumberVerified"": true
            }
            ";

            client.AddResponse(200, response1);
            string response2 = @"
            {
                 ""id"" : ""0398e67a-818d-47ee-83fb-3519a6197b81"",
                 ""expires_in"" : 148478248144076800,
                 ""access_token"" : ""abcdefghijklmeopqrstuvwxyz0123456789""
            }
            ";

            client.AddResponse(200, response2);
            client.AddResponse(200, response1);

            KiiUser user = KiiUser.BuilderWithPhone("09011112222").Build();

            user.Country = "JP";
            bool      done      = false;
            KiiUser   user2     = null;
            Exception exception = null;

            user.Register("pass1234", (KiiUser created, Exception e) =>
            {
                done      = true;
                user2     = created;
                exception = e;
            });
            Assert.IsTrue(done);
            Assert.IsNotNull(user2);
            Assert.IsNull(exception);

            Assert.AreEqual("0398e67a-818d-47ee-83fb-3519a6197b81", user2.ID);
            Assert.AreEqual("09011112222", user2.Phone);
        }
Пример #33
0
        public void TestRequestUrl()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.SG);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory      = factory;
            Kii.AsyncHttpClientFactory = factory;
            MockHttpClient client = (MockHttpClient)factory.Client;

            // send request
            client.AddResponse(200, "{" +
                               "\"id\" : \"user1234\"," +
                               "\"access_token\" : \"cdef\"," +
                               "\"expires_in\" : 9223372036854775}");
            KiiUser.LogIn("kii1234", "pass1234");

            // check request url
            Assert.AreEqual("https://api-sg.kii.com/api/oauth2/token", client.RequestUrl [0]);
        }
Пример #34
0
        public void Test_UserScopeSync()
        {
            LogIn("test-user-00001");
            AddMockResponse(200, new string[] { "Topic1", "Topic2" }, null);
            string userID = "test_user";
            KiiListResult <KiiTopic> topics = KiiUser.UserWithID(userID).ListTopics();

            Assert.IsFalse(topics.HasNext);
            Assert.IsNull(topics.PaginationKey);
            Assert.AreEqual(2, topics.Result.Count);
            Assert.AreEqual("Topic1", topics.Result[0].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("users", userID, "topics", "Topic1"), topics.Result[0].Uri.ToString());
            Assert.AreEqual("Topic2", topics.Result[1].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("users", userID, "topics", "Topic2"), topics.Result[1].Uri.ToString());

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "users", userID, "topics"), client.RequestUrl [0]);
            Assert.AreEqual("Bearer " + KiiUser.AccessToken, client.RequestHeader [0]["Authorization"]);
        }
Пример #35
0
    public void sendRegistrationData(RegistrationData registrationData, MethodReferenceWithResponse responseHandler)
    {
        Response response  = (Response)gameObject.AddComponent("Response");
        bool     inHandler = true;

        Debug.Log("Attempting registration...");
        if (registrationData.password.Equals(registrationData.passwordConfirm))
        {
            Debug.Log("Creating user builder");
            KiiUser.Builder builder;
            builder = KiiUser.BuilderWithName(registrationData.username);
            builder.WithEmail(registrationData.email);
            KiiUser user = builder.Build();
            Debug.Log("Attempting signup...");
            user.Register(registrationData.password, (KiiUser user2, Exception e) => {
                if (e != null)
                {
                    response.error   = true;
                    response.message = "Signup failed: " + e.ToString();
                    inHandler        = false;
                    Debug.Log("Signup failed: " + e.ToString());
                }
                else
                {
                    response.error   = false;
                    response.message = "";
                    inHandler        = false;
                    Debug.Log("Signup succeeded");
                }
            });
        }
        else
        {
            response.error   = true;
            response.message = "Passwords don't match!";
            inHandler        = false;
        }
        // Calling response handler:
        while (inHandler)
        {
        }
        responseHandler(response);
    }
Пример #36
0
    public void sendLoginData(LoginData loginData, MethodReferenceWithResponse responseHandler)
    {
        Response response = (Response)gameObject.AddComponent<Response>();

        Debug.Log("Sending login request to Kii Cloud");

        try {
            user = KiiUser.LogIn(loginData.username, loginData.password);
            response.error = false;
            response.message = "";
            Debug.Log("User log-in successful");
        }
        catch(Exception e){
            response.error = true;
            response.message = e.Message;
            Debug.Log(e.Message);
        }

        // Calling response handler
        responseHandler(response);
    }
Пример #37
0
    void PerformRemoveUser(KiiUser user)
    {
        message = "Removing user...";
        ButtonEnabled = false;

        currentGroup.RemoveUser(user);
        currentGroup.Save((KiiGroup group, Exception e) =>
                          {
            ButtonEnabled = true;
            if (e != null)
            {
                message = "Failed to remove user " + e.ToString();
                return;
            }
            message = "Remove user succeeded";
        });
    }
Пример #38
0
    private void register()
    {
        user = null;
        OnCallback = true;
        KiiUser built_user = KiiUser.BuilderWithName (username).Build ();
        built_user.Register(password, (KiiUser user2, Exception e) => {
            if (e == null)
            {
                user = user2;
                Debug.Log ("Register completed");
            } else {
                user = null;
                OnCallback = false;
                Debug.Log ("Register failed : " + e.ToString());
            }

        });
    }
Пример #39
0
 public static void RegisterDamage(string target, float amount, float totalHealth, float gameTime, Vector3 direction)
 {
     Debug.Log("Getting KiiUser");
     user = KiiUser.CurrentUser;
     if(user == null)
         return;
     Debug.Log("Creating app bucket");
     appBucket = Kii.Bucket(BUCKET_NAME);
     Debug.Log("Creating damage object");
     KiiObject damage = appBucket.NewKiiObject();
     damage ["user"] = user.Username;
     damage ["target"] = target;
     damage ["time"] = gameTime;
     damage ["health"] = totalHealth;
     damage ["amount"] = amount;
     damage ["direction"] = direction;
     Debug.Log ("Saving damage object...");
     damage.Save((KiiObject obj, Exception e) => {
         if (e != null){
             Debug.Log ("GameScore: Failed to create damage object: " + e.ToString());
         } else {
             Debug.Log ("GameScore: Create damage object succeeded");
         }
     });
 }
Пример #40
0
    void UserCreatedCallback(KiiUser callbackUser, System.Exception exc)
    {
        Debug.LogWarning(exc.Message);
        if (exc != null && exc as System.NullReferenceException == null) {
            // Error handling
            setErrText = "CREATE USER FAILURE: " + exc.Message;
            return;
        }
        setErrText = "CREATE USER SUCCESS " + callbackUser.Username;
        User = callbackUser;

        KiiObject origObj = callbackUser.Bucket("worlds").NewKiiObject();
        origObj["test"] = "true";
        origObj.Save(true, BucketCreatedCallback);
    }
Пример #41
0
    public static void RegisterDeath(GameObject deadObject)
    {
        if (Instance == null)
        {
            Debug.Log ("Game score not loaded");
            return;
        }

        int
            playerLayer = LayerMask.NameToLayer (Instance.playerLayerName),
            enemyLayer = LayerMask.NameToLayer (Instance.enemyLayerName);

        Debug.Log("Getting KiiUser");
        user = KiiUser.CurrentUser;

        if(user == null){
            if (deadObject.layer == playerLayer) {
                Instance.deaths++;
            } else if (deadObject.layer == enemyLayer) {
                Instance.kills [deadObject.name] = Instance.kills.ContainsKey (deadObject.name) ? Instance.kills [deadObject.name] + 1 : 1;
            } else {
                Instance.kills [deadObject.name] = Instance.kills.ContainsKey (deadObject.name) ? Instance.kills [deadObject.name] + 1 : 1;
            }
            return;
        }

        Debug.Log("Creating app bucket");
        appBucket = Kii.Bucket(BUCKET_NAME);

        Debug.Log("Creating death object");
        KiiObject death = appBucket.NewKiiObject();
        death["user"] = user.Username;
        death ["time"] = Time.time;

        if (deadObject.layer == playerLayer) {
            Instance.deaths++;
            death ["type"] = "Player";
            death ["count"] = Instance.deaths;
            Debug.Log ("Dead player counted");
            Debug.Log ("Saving death object");
        } else if (deadObject.layer == enemyLayer) {
            Instance.kills [deadObject.name] = Instance.kills.ContainsKey (deadObject.name) ? Instance.kills [deadObject.name] + 1 : 1;
            death ["type"] = "Enemy";
            death ["enemy"] = deadObject.name;
            death ["count"] = Instance.kills [deadObject.name];
            Debug.Log ("Dead enemy counted");
            Debug.Log ("Saving death object...");
        } else {
            Instance.kills [deadObject.name] = Instance.kills.ContainsKey (deadObject.name) ? Instance.kills [deadObject.name] + 1 : 1;
            death ["type"] = "Unknown";
            death ["enemy"] = deadObject.name;
            death ["count"] = Instance.kills [deadObject.name];
            Debug.Log ("Dead entity counted");
            Debug.Log ("Saving death object...");
        }

        death.Save((KiiObject obj, Exception e) => {
            if (e != null){
                Debug.Log ("GameScore: Failed to create death object: " + e.ToString());
            } else {
                Debug.Log ("GameScore: Create death object succeeded");
            }
        });
    }