/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $userManager = $this->container->get('fos_user.user_manager'); $admin = $userManager->createUser(); $admin->setUsername('*****@*****.**'); $admin->setFirstName('Admin'); $admin->setLastName('Website admin'); $admin->setEmail('*****@*****.**'); $admin->setPlainPassword('pad3dam'); $admin->setEnabled(true); $admin->setBirthday(new \DateTime('1941-04-14')); $admin->setRoles(array('ROLE_ADMIN')); $admin->setDescription('I am the admin user of padedam.lt website'); $userManager->updateUser($admin, true); $info = $userManager->createUser(); $info->setUsername('*****@*****.**'); $info->setFirstName('Info'); $info->setLastName('Website info'); $info->setEmail('*****@*****.**'); $info->setPlainPassword('pad3dam'); $info->setDescription('I am the info user of padedam.lt website'); $info->setEnabled(true); $info->setBirthday(new \DateTime('1945-04-14')); $info->setRoles(array('ROLE_USER')); $userManager->updateUser($info, true); $this->addReference('admin', $admin); $this->addReference('info', $info); //$this->getReference('sportas') }
/** * Vote * * This function is automatically called by the framework * * You can call it manually within a Controller with an $object/$attributes as argument * * The default $attributes will be the roles required for the current URL * * @param TokenInterface $token * @param object $object * @param array $attributes * * @return int */ public function vote(TokenInterface $token, $object, array $attributes) { $result = VoterInterface::ACCESS_ABSTAIN; foreach ($attributes as $attribute) { // Check if this Voter supports this Role if (!$this->supportsAttribute($attribute)) { continue; } // Get the Role Hierarchy $roleHierarchy = new RoleHierarchy($this->container->getParameter('security.role_hierarchy.roles')); // Get all the grantes roles from the Hierarchy $grantedRoles = $roleHierarchy->getReachableRoles($token->getRoles()); // ROLE_ADMIN has full access // Can't use ->isGranted because this method uses the Voters = (infinite loop)! foreach ($grantedRoles as $grantedRole) { if ($grantedRole->getRole() == 'ROLE_BACKEND_ADMIN') { return VoterInterface::ACCESS_GRANTED; } } // Get the current route // Need to use a Try Catch because subrequests (_fragment) can be voted... try { $route = $this->container->get('router')->match($this->container->get('request')->getPathInfo()); } catch (ResourceNotFoundException $e) { continue; } // If there is a section_id parameter in the Route if (array_key_exists('sectionId', $route)) { // Check is the user can access this Section if ($this->container->get('unifik_system.section_filter')->canAccess($route['sectionId'])) { return VoterInterface::ACCESS_GRANTED; } else { $result = VoterInterface::ACCESS_DENIED; } } } return $result; }