Beispiel #1
0
 /**
  * Create a new item.
  *
  * @param Request    $request
  * @param string|int $id
  *
  * @throws NotFoundHttpException
  * @throws RuntimeException
  * @throws UserProtectedException
  * @throws UserLimitReachedException
  *
  * @return mixed
  */
 public function __invoke(Request $request, $id)
 {
     /**
      * @var ResourceInterface
      */
     list($resourceType, $format) = $this->extractAttributes($request);
     /**
      * @var User
      */
     $data = $this->getItem($this->dataProvider, $resourceType, $id);
     $context = $resourceType->getDenormalizationContext();
     $context['object_to_populate'] = $data;
     if ($data->isProtected()) {
         throw new UserProtectedException();
     }
     $data = $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $context);
     if ($data->isActive()) {
         if ($this->userService->checkUserLimit()) {
             throw new UserLimitReachedException();
         }
     }
     $this->userService->syncData($data);
     $data->setNewPassword('');
     $data->setPassword('');
     $data->setLegacy(false);
     return $data;
 }
 public function __invoke(Request $request)
 {
     if ($this->container->hasParameter('partkeepr.auth.allow_password_change') && $this->container->getParameter('partkeepr.auth.allow_password_change') === false) {
         throw new PasswordChangeNotAllowedException();
     }
     $user = $this->userService->getUser();
     if (!$request->request->has('oldpassword') && !$request->request->has('newpassword')) {
         throw new \Exception('old password and new password need to be specified');
     }
     $FOSUser = $this->userManager->findUserByUsername($user->getUsername());
     if ($FOSUser !== null) {
         $encoder = $this->encoderFactory->getEncoder($FOSUser);
         $encoded_pass = $encoder->encodePassword($request->request->get('oldpassword'), $FOSUser->getSalt());
         if ($FOSUser->getPassword() != $encoded_pass) {
             throw new OldPasswordWrongException();
         }
         $this->userManipulator->changePassword($user->getUsername(), $request->request->get('newpassword'));
     } else {
         if ($user->isLegacy()) {
             if ($user->getPassword() !== md5($request->request->get('oldpassword'))) {
                 throw new OldPasswordWrongException();
             }
             $user->setNewPassword($request->request->get('newpassword'));
             $this->userService->syncData($user);
         } else {
             throw new \Exception('Cannot change password for LDAP users');
         }
     }
     $user->setPassword('');
     $user->setNewPassword('');
     return $user;
 }
 /**
  * Marks all tips as unread
  *
  * @param Request $request The request
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  *
  * @throws RuntimeException
  */
 public function __invoke(Request $request)
 {
     $dql = "DELETE FROM PartKeepr\\TipOfTheDayBundle\\Entity\\TipOfTheDayHistory th WHERE th.user = :user";
     $query = $this->entityManager->createQuery($dql);
     $query->setParameter("user", $this->userService->getUser());
     $query->execute();
     return new Response("OK");
 }
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @throws \Exception                                 If the format is invalid
  * @throws RuntimeException|RootNodeNotFoundException
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  */
 public function __invoke(Request $request)
 {
     $user = $this->userService->getUser();
     if ($request->request->has('preferenceKey')) {
         $this->userPreferenceService->deletePreference($user, $request->request->get('preferenceKey'));
     } else {
         throw new \Exception('Invalid format');
     }
 }
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @throws RuntimeException|RootNodeNotFoundException
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  */
 public function __invoke(Request $request)
 {
     $user = $this->userService->getUser();
     $preferences = $this->userPreferenceService->getPreferences($user);
     list($resourceType) = $this->extractAttributes($request);
     /*
      * @var ResourceInterface $resourceType
      */
     $serializedData = $this->serializer->normalize($preferences, 'json', $resourceType->getNormalizationContext());
     return new JsonResponse($serializedData);
 }
Beispiel #6
0
 public function __invoke(Request $request)
 {
     $user = $this->userService->getUser();
     $userPreferences = $this->userPreferenceService->getPreferences($user);
     $arrayUserPreferences = array();
     foreach ($userPreferences as $userPreference) {
         $arrayUserPreferences[] = array("preferenceKey" => $userPreference->getPreferenceKey(), "preferenceValue" => $userPreference->getPreferenceValue());
     }
     $user->setInitialUserPreferences(json_encode($arrayUserPreferences));
     return $user;
 }
 /**
  * Returns an item to delete.
  *
  * @param Request    $request
  * @param string|int $id
  *
  * @return mixed
  *
  * @throws NotFoundHttpException
  * @throws RuntimeException
  * @throws UserProtectedException
  */
 public function __invoke(Request $request, $id)
 {
     list($resourceType) = $this->extractAttributes($request);
     /**
      * @var User $item
      */
     $item = $this->getItem($this->dataProvider, $resourceType, $id);
     if ($item->isProtected()) {
         throw new UserProtectedException();
     }
     $this->userService->deleteFOSUser($item);
     return $item;
 }
 /**
  * Marks a specific tip as read.
  *
  * @param Request $request The request
  * @param int     $id      The ID of the system notice
  *
  * @throws RuntimeException
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  */
 public function __invoke(Request $request, $id)
 {
     list($resourceType) = $this->extractAttributes($request);
     $tip = $this->getItem($this->dataProvider, $resourceType, $id);
     /*
      * @var $tip TipOfTheDay
      */
     $tipOfTheDayHistoryItem = new TipOfTheDayHistory();
     $tipOfTheDayHistoryItem->setUser($this->userService->getUser());
     $tipOfTheDayHistoryItem->setName($tip->getName());
     $this->entityManager->persist($tipOfTheDayHistoryItem);
     $this->entityManager->flush();
     return $tip;
 }
 /**
  * Retrieves a filtered tip of the day history list. Filters by the currently logged in user by default
  *
  * @param Request $request
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  *
  * @throws RuntimeException
  */
 public function __invoke(Request $request)
 {
     list($resourceType) = $this->extractAttributes($request);
     $collection = $this->dataProvider->getCollection($resourceType);
     $user = $this->userService->getUser();
     $resultCollection = array();
     foreach ($collection as $item) {
         /**
          * @var $item TipOfTheDayHistory
          */
         if ($item->getUser() == $user) {
             $resultCollection[] = $item;
         }
     }
     return $resultCollection;
 }
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  * @throws \Exception If the format is invalid
  *
  * @throws RuntimeException|RootNodeNotFoundException
  */
 public function __invoke(Request $request)
 {
     $user = $this->userService->getUser();
     $data = json_decode($request->getContent());
     if (property_exists($data, "preferenceKey") && property_exists($data, "preferenceValue")) {
         $preference = $this->userPreferenceService->setPreference($user, $data->preferenceKey, $data->preferenceValue);
     } else {
         throw new \Exception("Invalid format");
     }
     list($resourceType) = $this->extractAttributes($request);
     /**
      * @var ResourceInterface $resourceType
      */
     $serializedData = $this->serializer->normalize($preference, 'json', $resourceType->getNormalizationContext());
     return new JsonResponse($serializedData);
 }
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request The request
  * @param int $id The ID of the part
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  *
  * @throws RuntimeException|RootNodeNotFoundException
  */
 public function __invoke(Request $request, $id)
 {
     list($resourceType) = $this->extractAttributes($request);
     $part = $this->getItem($this->dataProvider, $resourceType, $id);
     /**
      * @var $part Part
      */
     $quantity = $request->request->get("quantity");
     $user = $this->userService->getUser();
     $stock = new StockEntry(0 - intval($quantity), $user);
     if ($request->request->has("comment") && $request->request->get("comment") !== null) {
         $stock->setComment($request->request->get("comment"));
     }
     $part->addStockEntry($stock);
     $this->registry->getManager()->persist($stock);
     $this->registry->getManager()->flush();
     return $part;
 }
Beispiel #12
0
 /**
  * Create a new item.
  *
  * @param Request $request
  *
  * @return mixed
  *
  * @throws NotFoundHttpException
  * @throws RuntimeException
  * @throws UserLimitReachedException
  */
 public function __invoke(Request $request)
 {
     /**
      * @var $resourceType ResourceInterface
      */
     list($resourceType, $format) = $this->extractAttributes($request);
     if ($this->userService->checkUserLimit() === true) {
         throw new UserLimitReachedException();
     }
     /**
      * @var User $data
      */
     $data = $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $resourceType->getDenormalizationContext());
     $data->setProvider($this->userService->getBuiltinProvider());
     $data->setLegacy(false);
     $this->userService->syncData($data);
     $data->setNewPassword("");
     $data->setPassword("");
     return $data;
 }
Beispiel #13
0
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request The request
  * @param int     $id      The ID of the part
  *
  * @throws RuntimeException|RootNodeNotFoundException
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  */
 public function __invoke(Request $request, $id)
 {
     list($resourceType) = $this->extractAttributes($request);
     $part = $this->getItem($this->dataProvider, $resourceType, $id);
     /*
      * @var $part Part
      */
     $quantity = $request->request->get('quantity');
     $user = $this->userService->getUser();
     $oldQuantity = $part->getStockLevel();
     $correctionQuantity = $quantity - $oldQuantity;
     if ($correctionQuantity != 0) {
         $stock = new StockEntry();
         $stock->setStockLevel($correctionQuantity);
         $stock->setUser($user);
         if ($request->request->has('comment') && $request->request->get('comment') !== null) {
             $stock->setComment($request->request->get('comment'));
         }
         $part->addStockLevel($stock);
         $this->registry->getManager()->persist($stock);
         $this->registry->getManager()->flush();
     }
     return $part;
 }