Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Updating fields for ParseUsers

I am using ParseUser for user management. Having the username (unique), I planned to query the User class to identify the user and then put a new score to the "score" field, just like a Leaderboard. Coded as follows:

Code:

public void update_user_score(String username, int original_score, int add)
{
    final int new_score = original_score + add;  
    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.whereEqualTo("username", username);
    query.setLimit(1);

    query.findInBackground(new FindCallback() 
    {
          public void done(final ParseObject object, ParseException e) 
          {
            if (e == null) 
            {
                object.saveInBackground(new SaveCallback() 
                {
                    public void done(ParseException e) 
                    {
                        object.put("score", new_score);                                 
                        object.saveInBackground();                                      
                        onBackPressed();                            
                    }
                });
            }
          }
    });
}

Situation: It states that The type new FindCallback(){} must implement the inherited abstract method FindCallback.done(List, ParseException) . I have tried that FindCallback.done and found it unsucessful.

Question:

I would like to ask how the other fields of the user be updated with the username given? Thanks!

like image 712
pearmak Avatar asked May 22 '15 16:05

pearmak


2 Answers

As per the parse documentation said,

The ParseUser class is secured by default. Data stored in a ParseUser can only be modified by that user. By default, the data can still be read by any client. Thus, some ParseUser objects are authenticated and can be modified, whereas others are read-only.

Specifically, you are not able to invoke any of the save or delete type methods unless the ParseUser was obtained using an authenticated method, like logIn or signUp. This ensures that only the user can alter their own data.

The following illustrates this security policy:

ParseUser user = ParseUser.logIn("my_username", "my_password");
user.setUsername("my_new_username"); // attempt to change username
user.saveInBackground(); // This succeeds, since the user was authenticated on the device

// Get the user from a non-authenticated manner
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.getInBackground(user.getObjectId(), new GetCallback<ParseUser>() {
  public void done(ParseUser object, ParseException e) {
    object.setUsername("another_username");

    // This will throw an exception, since the ParseUser is not authenticated
    object.saveInBackground();
  }
});

please go through this link Reference

like image 156
Karan Maru Avatar answered Oct 05 '22 12:10

Karan Maru


public void update_user_score(String username, int original_score, int add)
{
  final int new_score = original_score + add;  
  ParseQuery<ParseUser> query = ParseUser.getQuery();
  query.whereEqualTo("username", username);
  query.setLimit(1);

query.findInBackground(new FindCallback() 
{
      public void done(final ParseUser object, ParseException e) 
      {
        if (e == null) 
        {   
            object.put("score", new_score);
            object.saveInBackground(new SaveCallback() 
            {
                public void done(ParseException e) 
                {

                    if(e==null)                                   
                    onBackPressed();                            
                }
            });
        }
      }
});
}
like image 27
hemanth1488 Avatar answered Oct 05 '22 12:10

hemanth1488