/**
  * Returns a new UserQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   UserQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return UserQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof UserQuery) {
         return $criteria;
     }
     $query = new UserQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 /**
  * @param \JesseMaxwell\PrayerBundle\Model\PrayerRequest $prayerRequest
  */
 public function verifyPrayerRequestRelationship(PrayerRequest $prayerRequest)
 {
     $user = UserQuery::create()->findOneByUsername($this->username);
     if ($prayerRequest && $user->getId() !== $prayerRequest->getUserId()) {
         throw new HttpException(403, 'You are not allowed to access that prayer request.');
     }
 }
 public function validate($value, Constraint $context)
 {
     $userId = UserQuery::create()->findIdByUsername($this->username);
     $matchFound = PrayerRequestQuery::create()->findIfUserHasRequest($value, $userId);
     if ($matchFound) {
         throw new HttpException(409, "You already have a prayer request titled that.");
     }
 }
 /**
  * @ApiDoc(
  *      section="Request",
  *      description="Returns a list of all a users requests",
  *      requirements={
  *          {
  *              "name"="username",
  *              "dataType"="integer",
  *              "requirement"="\d+",
  *              "description"="Provided username to verify authenticity of the request."
  *          }
  *      },
  *      statusCodes={
  *          200="Returned when successful",
  *          401="Returned when your username is not valid.",
  *          404="Returned when no prayer prayer requests are associated with that user"
  *      },
  * )
  *
  * @Rest\View()
  * @Route("/request/all", name="_get_all_requests")
  * @Method("GET")
  */
 public function getAllRequestsAction()
 {
     $userId = UserQuery::create()->findOneByUsername($this->get('request')->attributes->get('username'))->getId();
     $prayerRequests = PrayerRequestQuery::create()->select(array('Id', 'Title', 'Description', 'Date', 'Answered'))->filterBy('UserId', $userId)->find();
     if (!$prayerRequests) {
         throw new NotFoundHttpException("No prayer requests found.");
     }
     return array('prayer_requests' => $prayerRequests->toArray());
 }
 /**
  * @ApiDoc(
  *      section="Request",
  *      description="Returns a list of all a users requests",
  *      requirements={
  *          {
  *              "name"="username",
  *              "dataType"="integer",
  *              "requirement"="\d+",
  *              "description"="Provided username to verify authenticity of the request."
  *          }
  *      },
  *      statusCodes={
  *          200="Returned when successful",
  *          404="Returned when no prayer prayer requests are associated with that user"
  *      },
  * )
  *
  * @Rest\View()
  * @Route("/request/all", name="_get_all_requests")
  * @Method("GET")
  */
 public function getAllRequestsAction()
 {
     $userId = UserQuery::create()->findOneByUsername($this->get('request')->attributes->get('username'))->getId();
     $prayerRequests = PrayerRequestQuery::create()->findByUserId($userId);
     if (!$prayerRequests) {
         throw new NotFoundHttpException("No prayer requests found.");
     }
     return array('prayer_requests' => $prayerRequests->toArray());
 }
 public function onKernelController(FilterControllerEvent $event)
 {
     $currentUser = $event->getRequest()->attributes->get('username');
     $authUser = UserQuery::create()->findOneByUsername($currentUser);
     if (!$authUser && $currentUser) {
         throw new HttpException(401, "I'm sorry, but you are not authorized to access the system.");
     }
     if ($currentUser && !$authUser->getEnabled()) {
         throw new HttpException(403, "I'm sorry, but your account has been disabled. Please contact an administrator and request that they enable your account");
     }
 }
Esempio n. 7
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(UserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = UserQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 /**
  * @param \JesseMaxwell\PrayerBundle\Model\PrayerRequest $prayerRequest
  *
  * @return \FOS\RestBundle\View\View|\Symfony\Component\HttpFoundation\Response
  * @throws \Exception
  * @throws \PropelException
  */
 private function processRequest(PrayerRequest $prayerRequest)
 {
     $username = $this->get('request')->get('username');
     $userId = UserQuery::create()->findIdByUsername($username);
     $statusCode = $prayerRequest->isNew() ? 201 : 204;
     $headers = array();
     $prayerRequest->setUserId($userId);
     $prayerRequest = $this->setProvidedFields($prayerRequest);
     $errors = $this->get('validator')->validate($prayerRequest);
     if (count($errors) > 0) {
         return $this->view(array('errors' => $this->getErrorList($errors)), 400);
     }
     $prayerRequest->save();
     $content = array('id' => $prayerRequest->getId());
     if ($statusCode === 201) {
         $headers = array('Location' => $this->generateUrl("_get_request", array('username' => $username, 'id' => $prayerRequest->getId()), true));
     }
     return $this->view($content, $statusCode, $headers);
 }
 /**
  * @param \JesseMaxwell\PrayerBundle\Model\PrayerRequest $prayerRequest
  *
  * @return \FOS\RestBundle\View\View|\Symfony\Component\HttpFoundation\Response
  * @throws \Exception
  * @throws \PropelException
  */
 private function processForm(PrayerRequest $prayerRequest)
 {
     $request = $this->get('request');
     $userId = UserQuery::create()->findIdByUsername($request->get('username'));
     $statusCode = $prayerRequest->isNew() ? 201 : 204;
     $headers = null;
     $form = $this->createForm(new PrayerRequestType(), $prayerRequest, array('method' => 'PUT'));
     $form->handleRequest($request);
     $prayerRequest->setUserId($userId);
     if ($form->isValid()) {
         $prayerRequest->save();
         $content = array('id' => $prayerRequest->getId());
         if ($statusCode === 201) {
             $headers = array('Location' => $this->generateUrl("_get_request", array('username' => $request->get('username'), 'id' => $prayerRequest->getId()), true));
         }
         return $this->view($content, $statusCode, $headers);
     }
     return View::create($form, 400);
 }