예제 #1
0
 /**
  * Determines whether the current session token is revocable.
  * This method is useful for migrating an existing app to use
  * revocable sessions.
  *
  * @return boolean
  */
 public static function isCurrentSessionRevocable()
 {
     $user = ParseUser::getCurrentUser();
     if ($user) {
         return self::_isRevocable($user->getSessionToken());
     }
 }
예제 #2
0
 /**
  * Makes a call to a Cloud function
  *
  * @param string $name Cloud function name
  * @param array  $data Parameters to pass
  * @param boolean $useMasterKey Whether to use the Master Key
  *
  * @return mixed
  */
 public static function run($name, $data = array(), $useMasterKey = false)
 {
     $sessionToken = null;
     if (ParseUser::getCurrentUser()) {
         $sessionToken = ParseUser::getCurrentUser()->getSessionToken();
     }
     $response = ParseClient::_request('POST', '/1/functions/' . $name, $sessionToken, json_encode(ParseClient::_encode($data, null, false)), $useMasterKey);
     return ParseClient::_decode($response['result']);
 }
예제 #3
0
 public static function handleParseError(ParseException $e)
 {
     $code = $e->getCode();
     d($e);
     switch ($code) {
         case INVALID_SESSION_TOKEN:
             ParseUser::logout();
             // Redirect to login page
             break;
     }
 }
 /**
  * Parse\Client::initialize, must be called before using Parse features.
  *
  * @param string $app_id     Parse Application ID
  * @param string $rest_key   Parse REST API Key
  * @param string $master_key Parse Master Key
  *
  * @return null
  */
 public static function initialize($app_id, $rest_key, $master_key)
 {
     ParseUser::registerSubclass();
     ParseRole::registerSubclass();
     ParseInstallation::registerSubclass();
     self::$applicationId = $app_id;
     self::$restKey = $rest_key;
     self::$masterKey = $master_key;
     if (!static::$storage) {
         if (session_status() === PHP_SESSION_ACTIVE) {
             self::setStorage(new ParseSessionStorage());
         } else {
             self::setStorage(new ParseMemoryStorage());
         }
     }
 }
예제 #5
0
 /**
  * Link the user with Facebook details.
  *
  * @param string $id the Facebook user identifier
  * @param string $access_token the access token for this session
  * @param \DateTime $expiration_date defaults to 60 days
  * @param boolean $useMasterKey whether to override security
  *
  * @throws ParseException
  *
  * @return ParseUser
  */
 public function linkWithFacebook($id, $access_token, $expiration_date = null, $useMasterKey = false)
 {
     if (!$this->getObjectId()) {
         throw new ParseException("Cannot link an unsaved user, use ParseUser::logInWithFacebook");
     }
     if (!$id) {
         throw new ParseException("Cannot link Facebook user without an id.");
     }
     if (!$access_token) {
         throw new ParseException("Cannot link Facebook user without an access token.");
     }
     if (!$expiration_date) {
         $expiration_date = new \DateTime();
         $expiration_date->setTimestamp(time() + 86400 * 60);
     }
     $data = ["authData" => ["facebook" => ["id" => $id, "access_token" => $access_token, "expiration_date" => ParseClient::getProperDateFormat($expiration_date)]]];
     $result = ParseClient::_request("PUT", "/1/users/" . $this->getObjectId(), $this->getSessionToken(), json_encode($data), $useMasterKey);
     $user = new ParseUser();
     $user->_mergeAfterFetch($result);
     $user->handleSaveResult(true);
     return $user;
 }
예제 #6
0
 /**
  * Execute a find query and return the results.
  *
  * @param boolean $useMasterKey
  *
  * @return array
  */
 public function find($useMasterKey = false)
 {
     $sessionToken = null;
     if (ParseUser::getCurrentUser()) {
         $sessionToken = ParseUser::getCurrentUser()->getSessionToken();
     }
     $queryString = $this->buildQueryString($this->_getOptions());
     $result = ParseClient::_request('GET', '/1/classes/' . $this->className . '?' . $queryString, $sessionToken, null, $useMasterKey);
     $output = array();
     foreach ($result['results'] as $row) {
         $obj = ParseObject::create($this->className, $row['objectId']);
         $obj->_mergeAfterFetchWithSelectedKeys($row, $this->selectedKeys);
         $output[] = $obj;
     }
     return $result;
 }
예제 #7
0
 /**
  * Returns true if this user is the current user.
  *
  * @return boolean
  */
 public function isCurrent()
 {
     if (ParseUser::getCurrentUser() && $this->getObjectId()) {
         if ($this->getObjectId() == ParseUser::getCurrentUser()->getObjectId()) {
             return true;
         }
     }
     return false;
 }
예제 #8
0
 /**
  * Save Object and unsaved children within.
  *
  * @param $target
  * @param bool   $useMasterKey Whether to use the Master Key.
  *
  * @return null
  *
  * @throws ParseException
  */
 private static function deepSave($target, $useMasterKey = false)
 {
     $unsavedChildren = array();
     $unsavedFiles = array();
     static::findUnsavedChildren($target, $unsavedChildren, $unsavedFiles);
     $sessionToken = null;
     if (ParseUser::getCurrentUser()) {
         $sessionToken = ParseUser::getCurrentUser()->getSessionToken();
     }
     foreach ($unsavedFiles as &$file) {
         $file->save();
     }
     $objects = array();
     // Get the set of unique objects among the children.
     foreach ($unsavedChildren as &$obj) {
         if (!in_array($obj, $objects, true)) {
             $objects[] = $obj;
         }
     }
     $remaining = $objects;
     while (count($remaining) > 0) {
         $batch = array();
         $newRemaining = array();
         foreach ($remaining as $key => &$object) {
             if (count($batch) > 40) {
                 $newRemaining[] = $object;
                 continue;
             }
             if ($object->canBeSerialized()) {
                 $batch[] = $object;
             } else {
                 $newRemaining[] = $object;
             }
         }
         $remaining = $newRemaining;
         if (count($batch) === 0) {
             throw new Exception("Tried to save a batch with a cycle.");
         }
         $requests = array();
         foreach ($batch as $obj) {
             $json = $obj->getSaveJSON();
             $method = 'POST';
             $path = '/1/classes/' . $obj->getClassName();
             if ($obj->getObjectId()) {
                 $path .= '/' . $obj->getObjectId();
                 $method = 'PUT';
             }
             $requests[] = array('method' => $method, 'path' => $path, 'body' => $json);
         }
         if (count($requests) === 1) {
             $req = $requests[0];
             $result = ParseClient::_request($req['method'], $req['path'], $sessionToken, json_encode($req['body']), $useMasterKey);
             $batch[0]->mergeAfterSave($result);
         } else {
             $result = ParseClient::_request('POST', '/1/batch', $sessionToken, json_encode(array("requests" => $requests)), $useMasterKey);
             $errorCollection = array();
             foreach ($batch as $key => &$obj) {
                 if (isset($result[$key]['success'])) {
                     $obj->mergeAfterSave($result[$key]['success']);
                 } else {
                     if (isset($result[$key]['error'])) {
                         $response = $result[$key];
                         $error = $response['error']['error'];
                         $code = isset($response['error']['code']) ? $response['error']['code'] : -1;
                         $errorCollection[] = array('error' => $error, 'code' => $code, 'object' => $obj);
                     } else {
                         $errorCollection[] = array('error' => 'Unknown error in batch save.', 'code' => -1, 'object' => $obj);
                     }
                 }
             }
             if (count($errorCollection)) {
                 throw new ParseAggregateException("Errors during batch save.", $errorCollection);
             }
         }
     }
 }
예제 #9
0
파일: ParseACL.php 프로젝트: uday21/order
 /**
  * Get the defaultACL.
  *
  * @return ParseACL
  * @ignore
  */
 public static function _getDefaultACL()
 {
     if (self::$defaultACLUsesCurrentUser && self::$defaultACL) {
         $last = self::$lastCurrentUser ? clone self::$lastCurrentUser : null;
         if (!ParseUser::getCurrentUser()) {
             return self::$defaultACL;
         }
         if ($last != ParseUser::getCurrentUser()) {
             self::$defaultACLWithCurrentUser = clone self::$defaultAC;
             self::$defaultACLWithCurrentUser->_setShared(true);
             self::$defaultACLWithCurrentUser->setUserReadAccess(ParseUser::getCurrentUser(), true);
             self::$defaultACLWithCurrentUser->setUserWriteAccess(ParseUser::getCurrentUser(), true);
             self::$lastCurrentUser = clone ParseUser::getCurrentUser();
         }
         return self::$defaultACLWithCurrentUser;
     }
     return self::$defaultACL;
 }