public function post_array($array, &$message)
 {
     $location = new Location();
     $location->name = $array["name"];
     $location->latitude = $array["latitude"];
     $location->longitude = $array["longitude"];
     $location->userid = $array["userid"];
     if (empty($location->userid)) {
         // add to logged in user by default
         $user = apiDB::getUserByEmail($_SERVER['PHP_AUTH_USER']);
         $location->userid = $user->id;
     } else {
         // check permission ...
         $user = apiDB::getUser($location->userid);
         if ($_SERVER['PHP_AUTH_USER'] != $user->email && $this->access <= 1) {
             $message = "Not authorized to update location for User " . $location->userid;
             return 401;
         }
     }
     if ($this->access < 1) {
         $message = "Not authorized to add any locations: guest or disabled account";
         return 401;
     }
     return apiDB::addLocation($location, $message);
 }
 public function get_array_all()
 {
     if (empty($this->userid)) {
         $user = apiDB::getUserByEmail($_SERVER['PHP_AUTH_USER']);
         $locations = apiDB::getUserLocations($user->id, $this->columnName());
         if (count($locations) == 1) {
             return apiDB::getLocationMeasurements($locations[0]->locationid, $user->userid, get_class($this));
         } else {
             $error = array();
             $error["ERROR"] = "cannot display all measurements - please specify a location ID";
             return $error;
             //This is a hack
         }
     }
     return apiDB::getLocationMeasurements($this->locationid, $this->userid, get_class($this));
 }
示例#3
0
 protected function verify()
 {
     if (empty($this->id)) {
         $user = apiDB::getUserByEmail($_SERVER['PHP_AUTH_USER']);
         $this->id = $user->id;
     }
     if (empty($this->id)) {
         return $this->_response("User id not set. Cannot run \"verify\" without a valid user id.", 404);
     }
     if (empty($_GET["token"])) {
         return $this->_response("No token specified. Cannot run \"verify\" without a valid \"token\" parameter.", 404);
     }
     $message = "";
     $code = apiDB::verifyUser($this->id, $_GET["token"], $message);
     return $this->_response($message, $code);
 }