Skip to content

Commit

Permalink
Merge pull request #64 from juvenn/v0.2
Browse files Browse the repository at this point in the history
Fix: 默认传递当前 user 的 sessionToken
  • Loading branch information
juvenn committed Jan 28, 2016
2 parents 18d7ee8 + 0ff7dc8 commit c9fe189
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/LeanCloud/LeanClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use LeanCloud\LeanObject;
use LeanCloud\LeanACL;
use LeanCloud\LeanFile;
use LeanCloud\LeanUser;
use LeanCloud\Operation\IOperation;
use LeanCloud\Storage\IStorage;
use LeanCloud\Storage\SessionStorage;
Expand Down Expand Up @@ -227,6 +228,10 @@ public static function buildHeaders($sessionToken, $useMasterKey) {
$h['X-LC-Sign'] .= ",master";
}

if (!$sessionToken) {
$sessionToken = LeanUser::getCurrentSessionToken();
}

if ($sessionToken) {
$h['X-LC-Session'] = $sessionToken;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/LeanUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use LeanCloud\LeanClient;
use LeanCloud\LeanUser;
use LeanCloud\LeanFile;
use LeanCloud\LeanQuery;
use LeanCloud\CloudException;
use LeanCloud\Storage\SessionStorage;

Expand Down Expand Up @@ -199,5 +200,18 @@ public function testCircularGetCurrentUser() {
$this->assertEquals($user2->getUsername(), "alice");
}

/*
* To test this case, it is necessary to set "find" permission
* to be session user, i.e. allow current logged in user to query only.
*
* @link https://github.com/leancloud/php-sdk/issues/62
*/
public function testFindUserWithSession() {
$user = LeanUser::logIn("alice", "blabla");
$query = new LeanQuery("_User");
// it should not raise: 1 Forbidden to find by class permission.
$query->first();
}

}

0 comments on commit c9fe189

Please sign in to comment.