parse-community / parse-php-sdk

The PHP SDK for Parse Platform
https://parseplatform.org/
Other
811 stars 346 forks source link

Cant remove Public Read from _User Object during a sign up. #389

Closed gateway closed 6 years ago

gateway commented 6 years ago

I need the ability to create a parse user from our backend admin tool and set proper ACL for only that user to be able to read/write to his or her object.

Our mobile client can set the ACL to the users object id created, this from what we understand only allows the user to be able to do any changes to the users object.

On the mobile client this is how we set it.

image

Doing almost the similar process with the PHP sdk doesnt seem to work.

  // Signup
  $user = new ParseUser();
  $user->setUsername($data['email']);
  $user->setPassword($data['password']);
  $user->setEmail($data['email']);
  try {
    $user->signUp();
    // deal with ACL stuff after user is created.
    $acl = new ParseACL($user);
    $acl->setPublicReadAccess(false);
    $acl->setPublicWriteAccess(false);
    //$acl->setUserWriteAccess($user, true);
    //$acl->setUserReadAccess($user, true);
    $user->save();
    $user->logOut();

Looking at the sdk it doesnt seem like you dan do this..

    $acl->setPublicReadAccess($user, false);
    $acl->setPublicWriteAccess($user, false);

Which the our mobile clients are doing..

Basically with the code above creates a row like this in our database.

image

Issue, or am I missing some sort of other function call to fix this?

gateway commented 6 years ago

After a bit of testing I found the solution and I'm posting it here just incase anyone runs into this..

$user = new ParseUser();
$user->setUsername("foo");
$user->setPassword("Q2w#4!o)df");
try {
    $user->signUp();
    $acl = ParseACL::createACLWithUser($user);
    $user->setACL($acl);
    $user->save();
} catch (ParseException $ex) {
    // error in $ex->getMessage();
}

the key being these two lines after the $user->signUp();

    $acl = ParseACL::createACLWithUser($user);
    $user->setACL($acl);