Beispiel #1
0
 /**
  * @param Params $params
  * @param bool   $allowDraft
  *
  * @return \Jobs\Entity\Job|object
  * @throws \Doctrine\ODM\MongoDB\LockException
  */
 public function get(Params $params, $allowDraft = false)
 {
     /* @var \Jobs\Repository\Job $jobRepository */
     $jobRepository = $this->repositoryService->get('Jobs/Job');
     $idFromRoute = $params('id', 0);
     $idFromQuery = $params->fromQuery('id', 0);
     $idFromSubForm = $params->fromPost('job', 0);
     $id = empty($idFromRoute) ? empty($idFromQuery) ? $idFromSubForm : $idFromQuery : $idFromRoute;
     if (empty($id) && $allowDraft) {
         $this->acl->__invoke('Jobs/Manage', 'new');
         $user = $this->auth->getUser();
         /** @var \Jobs\Entity\Job $job */
         $job = $jobRepository->findDraft($user);
         if (empty($job)) {
             $job = $jobRepository->create();
             $job->setIsDraft(true);
             $job->setUser($user);
             $this->repositoryService->store($job);
         }
         return $job;
     }
     $job = $jobRepository->find($id);
     if (!$job) {
         throw new \RuntimeException('No job found with id "' . $id . '"');
     }
     return $job;
 }
Beispiel #2
0
 public function indexAction()
 {
     if (!($user = $this->authenticationService->getUser())) {
         throw new UnauthorizedAccessException('You must be logged in.');
     }
     /** @var Request $request */
     $request = $this->getRequest();
     $this->form->bind($user);
     if ($request->isPost()) {
         $this->form->setData($request->getPost()->toArray());
         if ($this->form->isValid()) {
             $this->repositoryService->store($user);
             $vars = array('valid' => true);
             $this->notification()->success('Password successfully changed');
         } else {
             // form is invalid
             $vars = array('valid' => false);
             // @TODO the messages are distributed to the hierarchy of the subElements, either we reduce that to flat plain text, or we make a message handling in JS
             $messages = $this->form->getMessages();
             $this->notification()->error('Password could not be changed');
         }
     }
     $vars['form'] = $this->form;
     if ($request->isXmlHttpRequest()) {
         return new JsonModel($vars);
     }
     return $vars;
 }
 public function testStore()
 {
     $user = new User();
     $this->dm->expects($this->once())->method('persist')->with($user);
     $this->dm->expects($this->once())->method('flush')->with($user);
     $this->assertInstanceOf('\\Core\\Repository\\RepositoryService', $this->rs->store($user), '::store() method should returns $this');
 }
 public function generate(UserInterface $user, $daysToLive = 1, $storeUser = true)
 {
     $tokenHash = Rand::getString(64, $this->charList);
     $dateStr = sprintf('+ %d day', $daysToLive);
     $expirationDate = new \Datetime($dateStr);
     /* @todo We should consider using the Prototype Design Pattern here. */
     $token = new Token();
     $token->setHash($tokenHash)->setExpirationDate($expirationDate);
     $user->getTokens()->add($token);
     if ($storeUser) {
         $this->repositoryService->store($user);
     }
     return $tokenHash;
 }
Beispiel #5
0
 /**
  * Assign a template to a job posting
  *
  * @return JsonModel
  */
 public function templateAction()
 {
     try {
         $jobEntity = $this->initializeJob()->get($this->params());
         $jobEntity->setTemplate($this->params('template', 'default'));
         $this->repositoryService->store($jobEntity);
         $this->notification()->success('Template changed');
     } catch (\Exception $e) {
         $this->notification()->danger('Template not changed');
     }
     return new JsonModel(array());
 }