/** * * @param \Ephp\ACLBundle\Model\BaseUser $user * @param string $title * @param string $twig * @param array $params */ private function notify(\Ephp\ACLBundle\Model\BaseUser $user, $title, $twig, $params = array()) { $params['user'] = $user; $message = \Swift_Message::newInstance()->setSubject($title)->setFrom($this->container->getParameter('email_robot'))->setTo(trim($user->getEmail()))->setBody($this->renderView("{$twig}.txt.twig", $params))->addPart($this->renderView("{$twig}.html.twig", $params), 'text/html'); $message->getHeaders()->addTextHeader('X-Mailer', 'PHP v' . phpversion()); $this->get('mailer')->send($message); }
public function onKernelRequest(FilterControllerEvent $event) { $this->event = $event; $this->request = $event->getRequest(); $rc = $this->router->getRouteCollection(); /* @var $rc \Symfony\Component\Routing\RouteCollection */ $route = $rc->get($this->request->get('_route')); if (!$route) { return false; } $acl = $route->getOption('ACL'); try { // Verifico che sia stata richiesta la memorizzazione delle statistiche if ($acl && is_array($acl)) { if (!is_object($this->user)) { throw new \Exception('User not logged'); } // Opzioni default in caso di assenza $options = array_merge(array('in_role' => array(), 'out_role' => array()), $acl); // Trasformo i parametri in un array if (!is_array($options['in_role'])) { $options['in_role'] = array($options['in_role']); } if (!is_array($options['out_role'])) { $options['out_role'] = array($options['out_role']); } // Verifico che l'utente abbia il ruolo necessario per visualizzare la pagina $test_in = count($options['in_role']) == 0; foreach ($options['in_role'] as $role) { $test_in |= $this->user->hasRole($role); } if (!$test_in) { throw new \Exception("User doesn't have permission"); } $test_out = true; foreach ($options['out_role'] as $role) { $test_out &= !$this->user->hasRole($role); } if (!$test_out) { throw new \Exception("User doesn't have permission"); } } } catch (\Exception $e) { throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException($e->getMessage()); } }
private function show($rules) { $out = false; if (isset($rules['always'])) { $out = $rules['always']; } if (isset($rules['logged'])) { $out = $rules['logged'] ? is_object($this->user) : !is_object($this->user); } if (is_object($this->user) && isset($rules['in_role'])) { if (!is_array($rules['in_role'])) { $rules['in_role'] = array($rules['in_role']); } foreach ($rules['in_role'] as $role) { $out |= $this->user->hasRole($role); } } if (is_object($this->user)) { if (isset($rules['out_role'])) { if (!is_array($rules['out_role'])) { $rules['out_role'] = array($rules['out_role']); } $test = true; foreach ($rules['out_role'] as $role) { $test &= !$this->user->hasRole($role); } $out = $test; } if (isset($rules['license'])) { $active = $this->user->getActiveLicenses(); foreach ($rules['license'] as $gruppo => $licenses) { if (isset($active[$gruppo])) { $out &= in_array($active[$gruppo], $licenses); } else { $out = false; } } } } return $out; }
function __construct() { parent::__construct(); }
private function checkIpNoUser(BaseUser $user, $ip) { $qb = $this->createQueryBuilder('a')->where('a.ip = :ip')->setParameter('ip', $ip)->andWhere('a.user != :user')->setParameter('user', $user->getId())->setMaxResults(1); $access = $qb->getQuery()->getOneOrNullResult(); return is_null($access); }