示例#1
0
        public User GetUserById(string UserId)
        {
            Console.WriteLine("Getting User " + UserId + "...");

            RestRequest request = new RestRequest("{version}/admin/users/{id}", Method.GET);

            request.AddParameter("version", _ver, ParameterType.UrlSegment);
            request.AddParameter("id", UserId, ParameterType.UrlSegment);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("Authorization", _token.token_type + " " + _token.access_token, ParameterType.HttpHeader);

            IRestResponse  response    = _client.Execute(request);
            HttpStatusCode statusCode  = response.StatusCode;
            int            numericCode = (int)statusCode;

            if (numericCode != 200)
            {
                throw new FoundryException(response.ErrorMessage, numericCode, response.Content);
            }

            UserDataJson userData = JsonConvert.DeserializeObject <UserDataJson>(response.Content);

            User retrievedUser = userData.Data.UserAttributes;

            retrievedUser.ConfigureUserData(userData.Data);
            if (retrievedUser.Location != null)
            {
                retrievedUser.Location = GetLocationById(retrievedUser.LocationId);
            }

            Console.WriteLine("User Retrieved: " + retrievedUser.FirstName + " " + retrievedUser.LastName + "...");

            return(retrievedUser);
        }
示例#2
0
        public User UpdateUser(User MyUser)
        {
            RestRequest request = new RestRequest("{version}/admin/registration_sets/{id}", Method.PATCH);

            request.Parameters.Clear();
            request.AddParameter("version", _ver, ParameterType.UrlSegment);
            request.AddParameter("id", MyUser.UserId, ParameterType.UrlSegment);
            request.AddParameter("application/json", API.UserJson(MyUser), ParameterType.RequestBody);
            _client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(_token.access_token, _token.token_type);

            IRestResponse  response    = _client.Execute(request);
            HttpStatusCode statusCode  = response.StatusCode;
            int            numericCode = (int)statusCode;

            if (numericCode != 200)
            {
                throw new FoundryException(response.ErrorMessage, numericCode, response.Content);
            }

            UserDataJson userData = JsonConvert.DeserializeObject <UserDataJson>(response.Content);

            Console.WriteLine("User successfully updated.");

            User user = userData.Data.UserAttributes;

            if (user.Location != null)
            {
                user.Location = GetLocationById(user.LocationId);
            }

            user.ConfigureUserData(userData.Data);

            return(user);
        }
示例#3
0
    public static async Task <Boolean> WriteUser(UserDataJson userData, string userId)
    {
        bool ret = false;

        string json = JsonUtility.ToJson(userData);

        Task writeUserTask = reference.Child("users").Child(userId).SetRawJsonValueAsync(json);

        await writeUserTask;

        if (writeUserTask.IsCompleted)
        {
            ret = true;
        }

        return(ret);
    }
示例#4
0
 public static void SaveCloudUserData(string userId)
 {
     if (Application.internetReachability != NetworkReachability.NotReachable)
     {
         UserDataJson newCloudUserData = new UserDataJson();
         newCloudUserData.InitFromApplicationModel();
         FirebaseDatabaseHandler.WriteUser(newCloudUserData, userId).ContinueWith(task =>
         {
             if (task.Result)
             {
                 Debug.Log(String.Format("Write UserId: {0} to cloud succeed.", userId));
             }
             else
             {
                 Debug.LogError(String.Format("Write UserId: {0} to cloud failed.", userId));
             }
         });
     }
 }
示例#5
0
    IEnumerator LoadUserDataC(string userID)
    {
        string path = serverURL + GetUser + "?userID=" + userID;

        print("path" + path);
        WWW www = new WWW(path);

        yield return(www);

        if (www.error != null)
        {
            print("There was an error: " + www.error);
        }
        else
        {
            string result = www.text;
            print(result);
            UserDataJson userData = JsonUtility.FromJson <UserDataJson>(result);
            UserData.Instance.UpdateRetosValue(userData.retosGanados, userData.retosPerdidos);
        }
    }
示例#6
0
    public static void SyncUserData(UserDataBinary localUserData, UserDataJson cloudUserData)
    {
        if (localUserData == null && cloudUserData == null)
        {
            ApplicationModel.CurrentLevel      = 1;
            ApplicationModel.CurrentBoneNumber = 0;
            Debug.Log("No user data found.");
            return;
        }
        else if (localUserData == null || (localUserData != null && cloudUserData != null && localUserData.ModifiedDatetimeBinary <= cloudUserData.ModifiedDatetimeBinary))
        {
            ApplicationModel.CurrentLevel      = cloudUserData.Level;
            ApplicationModel.CurrentBoneNumber = cloudUserData.BoneNumber;
            ApplicationModel.SaveLocalUserData(FirebaseAuthHelper.Auth.CurrentUser.UserId);
            Debug.Log(String.Format("User data loaded from the cloud: {0}", FirebaseAuthHelper.Auth.CurrentUser.UserId));
        }
        else if (cloudUserData == null || (localUserData != null && cloudUserData != null && localUserData.ModifiedDatetimeBinary >= cloudUserData.ModifiedDatetimeBinary))
        {
            ApplicationModel.CurrentLevel      = localUserData.Level;
            ApplicationModel.CurrentBoneNumber = localUserData.BoneNumber;
            Debug.Log(String.Format("User data loaded from the local file: {0}", localUserData.UserID));

            UserDataJson newCloudUserData = new UserDataJson();
            newCloudUserData.InitFromApplicationModel();
            FirebaseDatabaseHandler.WriteUser(newCloudUserData, FirebaseAuthHelper.Auth.CurrentUser.UserId).ContinueWith(task =>
            {
                if (task.Result)
                {
                    Debug.Log(String.Format("Write UserId: {0} to cloud succeed.", FirebaseAuthHelper.Auth.CurrentUser.UserId));
                }
                else
                {
                    Debug.LogError(String.Format("Write UserId: {0} to cloud failed.", FirebaseAuthHelper.Auth.CurrentUser.UserId));
                }
            });
        }
    }
示例#7
0
    public static async Task <UserDataJson> GetUserByUserId(string userId)
    {
        UserDataJson ret = null;

        try
        {
            Task <DataSnapshot> getUserTask = reference.Child("users").Child(userId).GetValueAsync();

            await getUserTask;

            if (getUserTask.IsCompleted && getUserTask.Result != null)
            {
                var userString = getUserTask.Result.GetRawJsonValue();

                ret = JsonUtility.FromJson <UserDataJson>(userString);
            }
        }
        catch (FirebaseException ex)
        {
            Debug.LogError(ex.Message);
        }

        return(ret);
    }