private function extractUploadedFile() { if (empty($_FILES)) { throw new LudoDBException("No files uploaded", 400); } $file = array_shift($_FILES); $this->setValue('file_size', $file['size']); $this->setValue('display_name', $file['name']); $this->setValue('created_date', date("Y-m-d H:i:s")); $this->setValue('user_id', CurrentPlayer::getInstance()->getId()); $tempPath = $this->getTempPath($file['name']); $this->setValue('path_on_server', $tempPath); move_uploaded_file($file['tmp_name'], $tempPath); if (!file_exists($tempPath)) { copy($file['tmp_name'], $tempPath); if (!file_exists($tempPath)) { throw new LudoDBException("Could not write temp file " . $file['tmp_name'] . " to " . LudoDBRegistry::get(self::FILE_UPLOAD_KEY)); } } }
public function edit($data) { $cp = CurrentPlayer::getInstance(); if (!$cp->hasAccessTo(ChessRoles::EDIT_USERS) && $cp->getId() !== $this->getId()) { throw new LudoDBUnauthorizedException("You are not allowed to edit this user"); } if (!$cp->hasAccessTo(ChessRoles::EDIT_USERS)) { if (isset($data['user_access'])) { unset($data['user_access']); } } if (isset($values['password']) && !$values['password']) { unset($values['password']); } return parent::save($data); }
public function validateServiceData($service, $data) { if (!CurrentPlayer::getInstance()->hasAccessTo(ChessRoles::IMPORT_GAMES)) { throw new LudoDBUnauthorizedException("You do not have access to import games"); } return true; }
public function validateArguments($service, $arguments) { if (count($arguments) > 1) { return false; } switch ($service) { case 'read': return count($arguments) === 1 && is_numeric($arguments[0]); case 'save': $cp = CurrentPlayer::getInstance(); if (!$cp->hasAccessTo(ChessRoles::EDIT_GAMES) && !$cp->hasAccessTo(ChessRoles::IMPORT_GAMES)) { throw new LudoDBUnauthorizedException("Your are not authorized to save new games"); } return count($arguments) === 0 || is_numeric($arguments[0]); } return true; }