Esempio n. 1
0
 public function sendHttpStatusHeader($code)
 {
     include_once 'HttpStatusCode.class.php';
     $statusCode = new HttpStatusCode($code);
     header('HTTP/1.1 ' . $statusCode->getCode() . ' ' . $statusCode->getDefinition());
     return $statusCode;
 }
Esempio n. 2
0
 public function actionView($errorNum = '404')
 {
     if (is_array($errorNum)) {
         $errorNum = $errorNum['error'];
     } else {
         if (strpos($errorNum, '../') !== false) {
             $errorNum = '404';
         }
     }
     include_once '../classes/HttpStatusCode.class.php';
     $statusCode = new HttpStatusCode($errorNum);
     $this->setLayoutVar('pageTitle', $statusCode->getDefinition());
     $this->loadView($this->getControllerName() . '/' . $statusCode->getCode());
 }
Esempio n. 3
0
 public function __construct(AppRequest $appRequest)
 {
     $this->appRequest = $appRequest;
     $this->appResponseData = array();
     $this->appResponseViews = array();
     $this->appHttpResponse = HttpStatusCode::ok();
 }
Esempio n. 4
0
 public function validateUser($userName, $password, AuthenticationManager $authenticationManager)
 {
     ResultHelper::whenEqual($password, null, AppLabelUtil::$ERROR_USER_NOT_FOUND, HttpStatusCode::badRequest());
     $user = $this->userService->validateUser($userName, $password);
     ResultHelper::whenEmpty($user, AppLabelUtil::$ERROR_USER_NOT_FOUND, HttpStatusCode::unauthorized());
     $token = Hash::create("sha256", mcrypt_create_iv(64, MCRYPT_DEV_URANDOM), HASH_USER_TOKEN_KEY);
     $authenticationManager->createValidationToken($user->getId(), $user->getRole()->getName(), $token);
     return $this->userMapper->mapUserToDto($user, $token);
 }
 public function movePageRowDown($id)
 {
     $entityToMoveDown = $this->pageRowDao->get($id);
     ResultHelper::whenEmpty($entityToMoveDown, AppLabelUtil::$ERROR_APP_INTERNAL, HttpStatusCode::internalServerError());
     $entityToMoveUp = $this->pageRowDao->getEntityWithLowerPosition($entityToMoveDown);
     if (!empty($entityToMoveUp)) {
         $this->swapPageRowPositions($entityToMoveDown, $entityToMoveUp);
     }
 }
Esempio n. 6
0
 protected function validateErrorPage()
 {
     if ($this->getErrorPage() === null) {
         throw new AemosSystemCoreError("Fatal error: Error page not correctly set", HttpStatusCode::internalServerError());
     }
     if (!file_exists(WEB . DIRECTORY_SEPARATOR . $this->getErrorPage())) {
         throw new AemosSystemCoreError("Fatal error: Configured error page file not found", HttpStatusCode::internalServerError());
     }
 }
 public function update(ComponentImage $componentImage)
 {
     $result = $this->componentImageDao->get($componentImage->getId());
     ResultHelper::whenEmpty($result, AppLabelUtil::$ERROR_COMPONENT_NOT_FOUND, HttpStatusCode::badRequest());
     if ($result->getImage() != $componentImage->getImage()) {
         unlink($result->getImage());
     }
     return $this->componentImageDao->update($componentImage);
 }
Esempio n. 8
0
 public function initMappers()
 {
     if ($this->securityMapper->initSecurity($this->appRequest)) {
         $this->routeMapper->initControllers($this->appRequest);
         $this->render($this->pageMapper->initPages($this->appRequest));
     } else {
         throw new AemosCriticalException("unauthorized", HttpStatusCode::unauthorized());
     }
 }
 public function createResetToken(User $user)
 {
     ResultHelper::whenEmpty($user->getEmail(), AppLabelUtil::$ERROR_USER_NO_EMAIL, HttpStatusCode::internalServerError());
     $tokenHash = Hash::create("sha256", mcrypt_create_iv(64, MCRYPT_DEV_URANDOM), HASH_GENERAL_KEY);
     $this->mailService->setMailHeading(array($user->getEmail() => $user->getFirstName() . " " . $user->getLastName()));
     $this->mailService->setBody("Instellen van uw wachtwoord", "Beste gebruiker, gelieve de volgende link te gebruiken om uw wachtwoord in te stellen: " . URL . "#/reset/token/" . $tokenHash);
     $this->mailService->sendMail();
     $resetToken = $this->resetTokenFactory->createResetToken($user->getId(), $tokenHash);
     $this->resetTokenDao->create($resetToken);
 }
Esempio n. 10
0
 public function setParameterValue($parameterName, $value)
 {
     foreach ($this->getEntityFields() as $entityField) {
         if ($entityField->getParameterName() === $parameterName) {
             $this->setter($entityField->getParameterName(), $value);
             return 0;
         }
     }
     throw new InvalidArgumentException("Error while trying to set: " . get_called_class() . " does contain a parameter named " . $parameterName, HttpStatusCode::internalServerError());
 }
Esempio n. 11
0
 public function getObject($object, $required = false)
 {
     if (isset($this->getRequestData()[lcfirst(get_class($object))]) && !empty($this->getRequestData()[lcfirst(get_class($object))])) {
         return $this->mapDataToObject($this->getRequestData()[lcfirst(get_class($object))], $object);
     }
     if ($required) {
         throw new AemosCriticalException("Required object '" . get_class($object) . "' was not found or empty!", HttpStatusCode::badRequest());
     }
     return null;
 }
Esempio n. 12
0
 public static function hasValue($array, $field, $required = false)
 {
     if (isset($array[$field]) && !empty($array[$field])) {
         return $array[$field];
     }
     if ($required) {
         throw new AemosRestException("error.app.invalidData", HttpStatusCode::badRequest());
     }
     return null;
 }
 public function setNewPasswordForValidUser(ResetTokenDto $resetTokenDto)
 {
     ResultHelper::whenEmpty($resetTokenDto->getToken(), AppLabelUtil::$ERROR_RESET_TOKEN_INCOMPLETE, HttpStatusCode::badRequest());
     ResultHelper::whenEmpty($resetTokenDto->getUserName(), AppLabelUtil::$ERROR_RESET_TOKEN_INCOMPLETE, HttpStatusCode::badRequest());
     ResultHelper::whenEmpty($resetTokenDto->getPassword(), AppLabelUtil::$ERROR_RESET_TOKEN_INCOMPLETE, HttpStatusCode::badRequest());
     $user = $this->userService->getUserByUserName($resetTokenDto->getUserName());
     ResultHelper::whenEmpty($user, AppLabelUtil::$ERROR_RESET_TOKEN_INVALID, HttpStatusCode::badRequest());
     $validationToken = $this->restTokenService->getResetTokenByUserId($user->getId(), $resetTokenDto->getToken());
     ResultHelper::whenEmpty($validationToken, AppLabelUtil::$ERROR_RESET_TOKEN_INVALID, HttpStatusCode::unauthorized());
     $result = $this->userService->setNewPassWordForUserId($user->getId(), $resetTokenDto->getPassword());
     ResultHelper::whenEmpty($result, AppLabelUtil::$ERROR_RESET_TOKEN_INVALID, HttpStatusCode::unauthorized());
     $this->restTokenService->removeResetTokenOfUser($user->getId());
 }
 /**
  * @param $componentDto PageComponentDto
  * @param bool $nullable
  * @return Entity
  * @throws AemosRestException
  */
 public static function filter(PageComponentDto $componentDto, $nullable = false)
 {
     foreach (PageComponentType::getTypes() as $type) {
         if ($componentDto->getType() == $type) {
             $componentClass = "Component" . ucfirst($type);
             return ArrayHelper::mapDataToObject($componentDto->getComponent(), new $componentClass());
         }
     }
     if (!$nullable) {
         throw new AemosRestException(AppLabelUtil::$ERROR_COMPONENT_UNKNOWN, HttpStatusCode::badRequest());
     }
     return null;
 }
Esempio n. 15
0
 public function removeCompany($id)
 {
     $company = $this->companyDao->get($id);
     ResultHelper::whenEmpty($company, AppLabelUtil::$ERROR_COMPANY_NOT_FOUND, HttpStatusCode::badRequest());
     $this->companyDao->delete($company);
 }
Esempio n. 16
0
 protected function delete($id)
 {
     $class = $this->modelClass;
     $model = $class::getById($id);
     if (isset($model) && $model->delete()) {
         http_response_code(HttpStatusCode::ACCEPTED);
         return HttpStatusCode::getMessage(HttpStatusCode::ACCEPTED);
     }
     http_response_code(HttpStatusCode::NOT_ACCEPTABLE);
     return HttpStatusCode::getMessage(HttpStatusCode::NOT_ACCEPTABLE);
 }
Esempio n. 17
0
 public function send()
 {
     HttpStatusCode::getHeader($this->statusCode);
     print $this->response;
 }
 public function update(ComponentForm $componentForm)
 {
     $result = $this->componentFormDao->get($componentForm->getId());
     ResultHelper::whenEmpty($result, AppLabelUtil::$ERROR_COMPONENT_NOT_FOUND, HttpStatusCode::badRequest());
     return $this->componentFormDao->update($componentForm);
 }
 public function testGetHeaderText()
 {
     $this->assertThat($this->object->getHeaderText(), $this->equalTo('HTTP/1.0 200 OK'));
 }
Esempio n. 20
0
 public function uploadFileForUser($file, $id)
 {
     $user = $this->userDao->get($id);
     ResultHelper::whenEmpty($user, AppLabelUtil::$ERROR_USER_NOT_FOUND, HttpStatusCode::badRequest());
     $fileUploader = new FileUploader();
     $newFileName = $fileUploader->uploadFile($file["file"]["name"], $file["file"]["tmp_name"], WEB . "/assets/user/" . $user->getUsername() . "/cv/");
     $user->setFile($newFileName);
     return $this->userDao->update($user);
 }
Esempio n. 21
0
 private function verifyAuthenticationManager()
 {
     if ($this->authenticationManager == null || empty($this->authenticationManager) || !$this->authenticationManager instanceof AuthenticationManager) {
         throw new AemosSystemCoreError("AuthenticationManager is not properly configured", HttpStatusCode::internalServerError());
     }
 }
 public function removePageComponent($id)
 {
     $tmpEntity = $this->pageComponentService->getPageComponent($id);
     ResultHelper::whenEmpty($tmpEntity, AppLabelUtil::$ERROR_COMPONENT_NOT_FOUND, HttpStatusCode::badRequest());
     $type = PageComponentFilter::getComponentType($tmpEntity);
     ResultHelper::whenEmpty($type, AppLabelUtil::$ERROR_COMPONENT_NOT_FOUND, HttpStatusCode::badRequest());
     $typeGetter = "get" . ucfirst($type);
     $tmpComponent = $tmpEntity->{$typeGetter}();
     ResultHelper::whenEmpty($tmpComponent, AppLabelUtil::$ERROR_APP_INTERNAL, HttpStatusCode::internalServerError());
     $typeService = lcfirst(get_class($tmpComponent)) . "Service";
     $typeService->delete($tmpComponent);
     $this->pageComponentService->removePageComponent($id);
 }
 private function _callControllerMethod(AppRequest $appRequest, ControllerRoute $route)
 {
     if (!method_exists($this->calledController, $route->getRoutePointer()->getMethodName())) {
         throw new AemosCriticalException("unknown page method", HttpStatusCode::notFound());
     }
     call_user_func_array(array($this->calledController, $route->getRoutePointer()->getMethodName()), $route->getParameters($appRequest->getRequestUrl()));
 }