예제 #1
0
파일: OAIParser.php 프로젝트: arkuuu/publin
 /**
  * @param Request $request
  *
  * @return string
  */
 public function run(Request $request)
 {
     try {
         $this->clearResumptionTokens();
         $verb = $request->get('verb') ? $request->get('verb') : $request->post('verb');
         $resumptionToken = $request->get('resumptionToken') ? $request->get('resumptionToken') : $request->post('resumptionToken');
         $metadataPrefix = $request->get('metadataPrefix') ? $request->get('metadataPrefix') : $request->post('metadataPrefix');
         $from = $request->get('from') ? $request->get('from') : $request->post('from');
         $until = $request->get('until') ? $request->get('until') : $request->post('until');
         $set = $request->get('set') ? $request->get('set') : $request->post('set');
         $identifier = $request->get('identifier') ? $request->get('identifier') : $request->post('identifier');
         switch (true) {
             case $verb === 'Identify':
                 $xml = $this->identify();
                 break;
             case $verb === 'ListMetadataFormats':
                 $xml = $this->listMetadataFormats();
                 break;
             case $verb === 'ListSets':
                 $xml = $this->listSets($resumptionToken);
                 break;
             case $verb === 'ListIdentifiers':
                 $xml = $this->listIdentifiers($metadataPrefix, $from, $until, $set, $resumptionToken);
                 break;
             case $verb === 'ListRecords':
                 $xml = $this->listRecords($metadataPrefix, $from, $until, $set, $resumptionToken);
                 break;
             case $verb === 'GetRecord':
                 $xml = $this->getRecord($identifier, $metadataPrefix);
                 break;
             default:
                 throw new BadVerbException();
                 break;
         }
     } catch (BadArgumentException $e) {
         $xml = $this->createErrorResponse('badArgument');
     } catch (BadResumptionTokenException $e) {
         $xml = $this->createErrorResponse('badResumptionToken');
     } catch (BadVerbException $e) {
         $xml = $this->createErrorResponse('badVerb');
     } catch (CannotDisseminateFormatException $e) {
         $xml = $this->createErrorResponse('cannotDisseminateFormat');
     } catch (IdDoesNotExistException $e) {
         $xml = $this->createErrorResponse('idDoesNotExist');
     } catch (NoMetadataFormatsException $e) {
         $xml = $this->createErrorResponse('noMetadataFormats');
     } catch (NoRecordsMatchException $e) {
         $xml = $this->createErrorResponse('noRecordsMatch');
     } catch (NoSetHierarchyException $e) {
         $xml = $this->createErrorResponse('noSetHierarchy');
     }
     $xml->preserveWhiteSpace = false;
     $xml->formatOutput = true;
     return $xml->saveXML();
 }
예제 #2
0
 /** @noinspection PhpUnusedPrivateMethodInspection
  * @param Request $request
  *
  * @return bool
  */
 private function deleteUser(Request $request)
 {
     $user_id = Validator::sanitizeNumber($request->post('user_id'));
     if (!$user_id) {
         throw new UnexpectedValueException();
     }
     $model = new UserModel($this->db);
     return $model->delete($user_id);
 }
예제 #3
0
 /** @noinspection PhpUnusedPrivateMethodInspection
  * @param Request $request
  *
  * @return string
  * @throws Exception
  * @throws NotFoundException
  */
 private function login(Request $request)
 {
     $errors = array();
     if ($request->post('username') && $request->post('password')) {
         $username = Validator::sanitizeText($request->post('username'));
         $password = Validator::sanitizeText($request->post('password'));
         if ($this->auth->login($username, $password)) {
             $destination = !empty($_SESSION['referrer']) ? $_SESSION['referrer'] : Request::createUrl(array(), true);
             $this->redirect($destination);
         } else {
             $errors[] = 'Invalid user name or password';
         }
     }
     $view = new View('login', $errors);
     return $view->display();
 }
예제 #4
0
 /** @noinspection PhpUnusedPrivateMethodInspection
  * @param Request $request
  *
  * @return bool|mixed
  * @throws PermissionRequiredException
  * @throws exceptions\LoginRequiredException
  */
 private function addUrl(Request $request)
 {
     if (!$this->auth->checkPermission(Auth::EDIT_PUBLICATION)) {
         throw new PermissionRequiredException(Auth::EDIT_PUBLICATION);
     }
     $id = Validator::sanitizeNumber($request->get('id'));
     if (!$id) {
         throw new UnexpectedValueException();
     }
     $url_model = new UrlModel($this->db);
     $validator = $url_model->getValidator();
     if ($validator->validate($request->post())) {
         $data = $validator->getSanitizedResult();
         $url = new Url($data);
         try {
             return $url_model->store($url, $id);
         } catch (DBDuplicateEntryException $e) {
             $this->errors[] = 'This url is already assigned to this publication';
             return false;
         }
     } else {
         $this->errors = array_merge($this->errors, $validator->getErrors());
         return false;
     }
 }
예제 #5
0
 /** @noinspection PhpUnusedPrivateMethodInspection
  * @param Request $request
  *
  * @return bool|int
  * @throws PermissionRequiredException
  * @throws exceptions\LoginRequiredException
  */
 private function edit(Request $request)
 {
     if (!$this->auth->checkPermission(Auth::EDIT_KEYWORD)) {
         throw new PermissionRequiredException(Auth::EDIT_KEYWORD);
     }
     $id = Validator::sanitizeNumber($request->get('id'));
     if (!$id) {
         throw new UnexpectedValueException();
     }
     $validator = $this->model->getValidator();
     if ($validator->validate($request->post())) {
         $input = $validator->getSanitizedResult();
         $this->model->update($id, $input);
         return true;
     } else {
         $this->errors = array_merge($this->errors, $validator->getErrors());
         return false;
     }
 }
예제 #6
0
 /** @noinspection PhpUnusedPrivateMethodInspection
  * @param Request $request
  *
  * @return bool|int
  */
 private function changePassword(Request $request)
 {
     $password = Validator::sanitizeText($request->post('password'));
     if (!$password || !$this->auth->validateLogin($this->user->getName(), $password)) {
         $this->errors[] = 'Invalid current password';
         return false;
     }
     $password_new = Validator::sanitizeText($request->post('password_new'));
     $password_confirm = Validator::sanitizeText($request->post('password_confirm'));
     if (!$password_new || !$password_confirm) {
         $this->errors[] = 'New password required but invalid';
         return false;
     }
     if ($password_new !== $password_confirm) {
         $this->errors[] = 'Entered passwords are not the same';
         return false;
     }
     return $this->auth->setPassword($this->user->getName(), $password_new);
 }
예제 #7
0
 /** @noinspection PhpUnusedPrivateMethodInspection
  * @param Request $request
  *
  * @return bool
  * @throws \Exception
  */
 private function submit(Request $request)
 {
     $input = $this->model->formatPost($request->post());
     $_SESSION['input'] = $input;
     try {
         $result = $this->store_publication($input);
     } catch (DBDuplicateEntryException $e) {
         //$this->db->cancelTransaction();
         // TODO make single error messages for each case
         $this->errors[] = 'A publication with this name already exists or you tried to add the same author or keyword to this publication twice';
         return false;
     }
     if (empty($this->errors) && $result) {
         if ($this->next()) {
             return true;
         }
         $this->clearForm();
         $this->redirect(Request::createUrl(array('p' => 'browse', 'by' => 'recent')));
         return true;
     } else {
         return false;
     }
 }