/**
  * Prints the selected storage locations to a dedicated file
  * and returns the url to this file.
  */
 public function startExport()
 {
     $this->requireParameter("ids");
     $this->requireParameter("configuration");
     $this->requireParameter("objectType");
     $ids = explode(',', $this->getParameter("ids"));
     $configurationId = $this->getParameter("configuration");
     $objectType = $this->getParameter("objectType");
     $printerUser = null;
     if ($this->hasParameter("target") && $this->getParameter("target") != "") {
         $printerUser = UserManager::getInstance()->getUser($this->getParameter("target"));
     }
     // check object type for valid object types for security reasons.
     // See Select query below and be aware of SQL injection!
     if (!array_key_exists($objectType, $this->availableObjectTypes)) {
         throw new RendererNotFoundException("Object type is forbidden!", $objectType, array_keys($this->availableObjectTypes));
     }
     $configuration = PrintingJobConfigurationManager::getInstance()->getEntity($configurationId);
     $query = PartKeepr::getEM()->createQuery("SELECT s FROM {$objectType} s WHERE s.id IN (?1)");
     $query->setParameter(1, $ids);
     $dataToRender = $query->getResult();
     $renderingObjects = array();
     if ($configuration->getPageLayout() !== null) {
         $renderingObjects[] = $configuration->getPageLayout();
     }
     $renderer = RendererFactoryRegistry::getInstance()->getRendererFactory($configuration->getExportRenderer())->createInstance($renderingObjects, $configuration->getRendererConfiguration());
     $renderer->passRenderingData($dataToRender);
     $tempFile = tempnam("/tmp", "PWC");
     $renderer->storeResult($tempFile);
     $tmpFile = new TempUploadedFile();
     $tmpFile->replace($tempFile);
     $tmpFile->setOriginalFilename("generatedFile." . $renderer->getSuggestedExtension());
     PartKeepr::getEM()->persist($tmpFile);
     PartKeepr::getEM()->flush();
     //Create a job if we have a valid printer target
     if ($printerUser !== null) {
         $job = new PrintingJob();
         $job->setData($tmpFile);
         $job->setTarget($printerUser);
         PartKeepr::getEM()->persist($job);
         PartKeepr::getEM()->flush();
     }
     return array("fileid" => $tmpFile->getId());
 }
Beispiel #2
0
 /**
  * Logs in the given user. If the login was successful, a session is automatically started.
  *
  * @return array The data
  * @throws InvalidLoginDataException
  *
  * @ServiceCall(description="Authenticates a user against the system",
  * 				documentation="Authenticates a user and starts a new session upon success.",
  * 				returnValues={
  * 					@ServiceReturnValue(
  * 											name="username",
  * 											type="string:50",
  * 											description="The logged in username"
  * 										),
  * 					@ServiceReturnValue(
  * 											name="sessionid",
  * 											type="string:50",
  * 											description="The session ID"
  * 										),
  * 					@ServiceReturnValue(
  * 											name="admin",
  * 											type="boolean",
  *	 										description="True if the logged in user has admin rights"
  * 										),
  * 					@ServiceReturnValue(
  * 											name="userPreferences",
  * 											type="UserPreference[]",
  * 											description="An array of UserPreferences"
  * 										)
  * 					},
  * 				parameters={
  * 					@ServiceParameter(	name="username",
  * 										type="string:50",
  * 										required=true,
  * 										description="The username to authenticate"
  * 										),
  * 					@ServiceParameter(	name="password",
  * 										type="string:32",
  * 										required=true,
  * 										description="The password, hashed in MD5"
  * 										)
  * 				})
  *
  */
 public function login()
 {
     $this->requireParameter("username");
     $this->requireParameter("password");
     /* Build a temporary user */
     $user = new User();
     $user->setRawUsername($this->getParameter("username"));
     $user->setHashedPassword($this->getParameter("password"));
     $authenticatedUser = UserManager::getInstance()->authenticate($user);
     if ($authenticatedUser !== false) {
         /* Start Session */
         $session = SessionManager::getInstance()->startSession($authenticatedUser);
         $session->getUser()->updateSeen();
         $aPreferences = array();
         foreach ($session->getUser()->getPreferences() as $result) {
             $aPreferences[] = $result->serialize();
         }
         return array("sessionid" => $session->getSessionID(), "username" => $this->getParameter("username"), "admin" => $session->getUser()->isAdmin(), "userPreferences" => array("response" => array("data" => $aPreferences)));
     } else {
         throw new InvalidLoginDataException();
     }
 }
Beispiel #3
0
 /**
  * Test the helper methods for setting / getting / deleting user preferences
  */
 public function testUserPreference()
 {
     $username = "******";
     $user = new User($username, "123");
     PartKeepr::getEM()->persist($user);
     PartKeepr::getEM()->flush();
     $user->setPreference("test", "foo");
     $this->assertEquals("foo", $user->getPreferenceValue("test"));
     $this->assertEquals("foo", $user->getPreference("test")->getValue());
     $this->assertEquals(1, count($user->getPreferences()));
     $user->deletePreference("test");
     UserManager::getInstance()->deleteUser($user->getId());
 }
Beispiel #4
0
 /**
  * Deletes the user from the database.
  * @see PartKeepr\Service.RestfulService::destroy()
  */
 public function destroy()
 {
     if (!SessionManager::getCurrentSession()->getUser()->isAdmin()) {
         throw new \Exception("Permission denied");
     }
     $this->requireParameter("id");
     UserManager::getInstance()->deleteUser($this->getParameter("id"));
     return array("data" => null);
 }
 private function authenticateByUsername($username, $password)
 {
     /* Build a temporary user */
     $user = new User();
     $user->setRawUsername($username);
     $user->setHashedPassword($password);
     $authenticatedUser = UserManager::getInstance()->authenticate($user);
     if ($authenticatedUser !== false) {
         /* Start Session */
         $session = SessionManager::getInstance()->startSession($authenticatedUser);
         return $session->getSessionID();
     } else {
         throw new InvalidLoginDataException();
     }
 }