private function checkRole($roleSuffix, ResourceEvent $event) { $resource = $event->getResource(); $resourceName = $this->rm->getResourceName(get_class($resource)); $roleName = 'ROLE_' . strtoupper($resourceName) . '_' . $roleSuffix; $isGranted = $this->authorizationChecker->isGranted($roleName); if (!$isGranted) { throw new AccessDeniedHttpException('User does not have role ' . $roleName); } }
/** * Stores the object in the request. * * @param Request $request The request * @param ParamConverter $configuration Contains the name, class and options of the object * @return bool True if the object has been successfully set, else false * @throws NotFoundHttpException */ public function apply(Request $request, ParamConverter $configuration) { $fullClass = $this->rm->getFullClass($configuration->getClass()); $name = $configuration->getName(); $resourceData = json_encode($request->request->all()); try { parent::apply($request, $configuration); $this->deserializeResource($request, $fullClass, $resourceData, $name); return true; } catch (\LogicException $e) { return $this->treatDoctrineException($request, $fullClass, $resourceData, $name); } catch (NotFoundHttpException $e) { return $this->treatDoctrineException($request, $fullClass, $resourceData, $name); } }
public function sendAllGroup($pro, $event, $text) { $rep = $this->rm->getRepository(new User()); //Recupérer les utilisateurs de pro en fonction de l'id du groupe $users = $rep->findAll(); foreach ($users as $user) { if ($user->getProfessional() == $pro) { $notif = new Notification(); $notif->setUser($user); $notif->setText($text); $notif->setType($event->getName()); $notif->setDatas(array($event->getResource())); $this->rm->create($notif); } } }
public function resetPassword(UserInterface $user) { if ($user->isPasswordRequestNonExpired(86400) == false) { $user->setConfirmationToken(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36)); $url = $this->host . $this->router->generate('asi_individual_password_is_reset', array('token' => $user->getConfirmationToken())); $today = new \DateTime(); $today->format('Y-m-d H:i:s'); $user->setPasswordRequestedAt($today); $this->rm->update($user); $event = new EventAssociatedWithUser($url, $user, null); $this->eventDispatcher->dispatch(User::USER_REQUESTED_NEW_PASSWORD, $event); return true; } return false; }
/** * @return UserRepository */ protected function getRepository() { return $this->rm->getRepository(new User()); }