Exemplo n.º 1
0
 /**
  * Dispatch onLogin hook
  *
  * @param array $body JSON decoded body params
  */
 private function dispatchOnLogin($body)
 {
     if (!Client::verifyHookSign("__on_login__User", $body["object"]["__sign"])) {
         error_log("Invalid hook sign for onLogin User" . " from {$this->env['REMOTE_ADDR']}");
         $this->renderError("Unauthorized.", 401, 401);
     }
     $userObj = Client::decode($body["object"], null);
     $meta["remoteAddress"] = $this->env["REMOTE_ADDR"];
     try {
         Cloud::runOnLogin($userObj, $meta);
     } catch (FunctionError $err) {
         $this->renderError($err->getMessage(), $err->getCode());
     }
     $this->renderJSON(array("result" => "ok"));
 }
Exemplo n.º 2
0
 /**
  * Merge data and metaData from server response
  *
  * @param array $data
  * @param array $meta Optional meta data
  */
 private function _mergeData($data, $meta = array())
 {
     // manually convert createdAt and updatedAt fields so they'll
     // be decoded as DateTime object.
     foreach (array("createdAt", "updatedAt") as $key) {
         if (isset($data[$key]) && is_string($data[$key])) {
             $data[$key] = array("__type" => "Date", "iso" => $data[$key]);
         }
     }
     foreach ($data as $key => $val) {
         $this->_data[$key] = Client::decode($val, $key);
     }
     foreach ($meta as $key => $val) {
         $this->_metaData[$key] = Client::decode($val, $key);
     }
 }
Exemplo n.º 3
0
 public function testDecodeGeoPoint()
 {
     $type = array('__type' => 'GeoPoint', 'latitude' => 39.9, 'longitude' => 116.4);
     $val = Client::decode($type, null);
     $this->assertTrue($val instanceof GeoPoint);
     $this->assertEquals(39.9, $val->getLatitude());
     $this->assertEquals(116.4, $val->getLongitude());
 }