getUser() публичный Метод

Returns the PartKeeprUser based on the user token within the Symfony2 environment.
public getUser ( ) : User
Результат PartKeepr\AuthBundle\Entity\User The proxy user
Пример #1
0
 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');
     }
 }
Пример #4
0
 /**
  * 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);
 }
Пример #5
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;
 }
Пример #6
0
 /**
  * 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;
 }
Пример #8
0
 /**
  * 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);
 }
Пример #9
0
 /**
  * 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;
 }
Пример #10
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;
 }