public function testSetRole() { // new entity $role = new Role(); // Use the setRole method $role->setRole("ROLE_ADMIN"); // Assert the result $this->assertEquals("ROLE_ADMIN", $role->getRole()); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $userRole = new Role(); $userRole->setName('User'); $userRole->setRole('ROLE_USER'); $userRole->setIsAllowedToSwitch(false); $manager->persist($userRole); $leadRole = new Role(); $leadRole->setName('Lead'); $leadRole->setRole('ROLE_LEAD'); $leadRole->setIsAllowedToSwitch(false); $leadRole->addRoleToHierarchy($userRole); $manager->persist($leadRole); $adminRole = new Role(); $adminRole->setName('Admin'); $adminRole->setRole('ROLE_ADMIN'); $adminRole->setIsAllowedToSwitch(false); $adminRole->addRoleToHierarchy($leadRole); $manager->persist($adminRole); $devRole = new Role(); $devRole->setName('Dev'); $devRole->setRole('ROLE_DEV'); $devRole->setIsAllowedToSwitch(true); $devRole->addRoleToHierarchy($adminRole); $manager->persist($devRole); $manager->flush(); $this->addReference('ROLE_USER', $userRole); $this->addReference('ROLE_LEAD', $leadRole); $this->addReference('ROLE_ADMIN', $adminRole); $this->addReference('ROLE_DEV', $devRole); $aclProvider = $this->container->get('security.acl.provider'); $devRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_DEV'); $adminRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_ADMIN'); $leadRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_LEAD'); $userRoleSecurityIdentity = new RoleSecurityIdentity('ROLE_USER'); $objectIdentity = ObjectIdentity::fromDomainObject($userRole); $acl = $aclProvider->createAcl($objectIdentity); $acl->insertObjectAce($userRoleSecurityIdentity, MaskBuilder::MASK_VIEW); $acl->insertObjectAce($devRoleSecurityIdentity, MaskBuilder::MASK_OPERATOR); $aclProvider->updateAcl($acl); $objectIdentity = ObjectIdentity::fromDomainObject($leadRole); $acl = $aclProvider->createAcl($objectIdentity); $acl->insertObjectAce($userRoleSecurityIdentity, MaskBuilder::MASK_VIEW); $acl->insertObjectAce($devRoleSecurityIdentity, MaskBuilder::MASK_OPERATOR); $aclProvider->updateAcl($acl); $objectIdentity = ObjectIdentity::fromDomainObject($adminRole); $acl = $aclProvider->createAcl($objectIdentity); $acl->insertObjectAce($userRoleSecurityIdentity, MaskBuilder::MASK_VIEW); $acl->insertObjectAce($devRoleSecurityIdentity, MaskBuilder::MASK_OPERATOR); $aclProvider->updateAcl($acl); $objectIdentity = ObjectIdentity::fromDomainObject($devRole); $acl = $aclProvider->createAcl($objectIdentity); $acl->insertObjectAce($devRoleSecurityIdentity, MaskBuilder::MASK_OPERATOR); $aclProvider->updateAcl($acl); }
protected function _loadRole(ObjectManager $manager) { $array = array(); $array[] = array('role' => 'ROLE_ADMIN', 'name' => 'Admin', 'use' => false); $array[] = array('role' => 'ROLE_STUDENT', 'name' => 'Student', 'use' => true); $array[] = array('role' => 'ROLE_UNCONFIRMED_TEACHER', 'name' => 'Teacher', 'use' => true); $array[] = array('role' => 'ROLE_TEACHER', 'name' => 'Teacher', 'use' => false); foreach ($array as $roles) { $role = new Role(); $role->setName($roles['name']); $role->setRole($roles['role']); $role->setUserole($roles['use']); $manager->persist($role); } $manager->flush(); }
/** * @Route("/verifyLogin") * @Route("/verifyLogin/") */ public function verifyLoginAction($getUsername, $getPassword) { $account = new account(); $em = $this->getDoctrine()->getManager(); $query = $em->createQueryBuilder()->select('COUNT(f.id)')->from('AppBundle:Account', 'f')->where('f.username = :username', 'f.password = :password')->setParameter('username', $getUsername)->setParameter('password', strtoupper(sha1($getUsername . ":" . $getPassword)))->getQuery(); $total = $query->getSingleScalarResult(); if ($total >= 1) { //logged in $role = new Role(); $role->setName(strtoupper($getUsername)); $role->setRole('ROLE_USER'); return $this->redirect('/account'); } else { //wrong password/username //die("wrong username/password"); return $this->redirect('/login/wrong-credentials'); } return $this->render('twitter/success_created.html.twig', array('getUsername' => $getUsername, 'getEmail' => $getEmail, 'current_year' => date("Y"))); }
public function load(ObjectManager $manager) { $role1 = new Role(); $role1->setName('Admin'); $role1->setRole('ROLE_ADMIN'); $manager->persist($role1); $role2 = new Role(); $role2->setName('Superadmin'); $role2->setRole('ROLE_SUPER_ADMIN'); $manager->persist($role2); $role3 = new Role(); $role3->setName('User'); $role3->setRole('ROLE_USER'); $manager->persist($role3); $role4 = new Role(); $role4->setName('Highest admin'); $role4->setRole('ROLE_HIGHEST_ADMIN'); $manager->persist($role4); $manager->flush(); $this->addReference('role-1', $role1); $this->addReference('role-2', $role2); $this->addReference('role-3', $role3); $this->addReference('role-4', $role4); }
public function load(ObjectManager $manager) { $user = new User(); $user->setUsername('admin'); $user->setUserFirstName('stamat'); $user->setUserLastName('stamativan'); $user->setEmail('*****@*****.**'); $user->setApiKey(null); $encoder = $this->container->get('security.password_encoder'); $password = $encoder->encodePassword($user, 'faster'); $user->setPassword($password); $manager->persist($user); $manager->flush(); $user2 = new User(); $user2->setUsername('suxorr'); $user2->setUserFirstName('mario'); $user2->setUserLastName('hristev'); $user2->setEmail('*****@*****.**'); $user2->setApiKey(null); $encoder2 = $this->container->get('security.password_encoder'); $password2 = $encoder2->encodePassword($user2, 'azsammario123'); $user2->setPassword($password2); $manager->persist($user2); $manager->flush(); $user3 = new User(); $user3->setUsername('teacher'); $user3->setUserFirstName('Пешо'); $user3->setUserLastName('Петкоф'); $user3->setEmail('*****@*****.**'); $user3->setApiKey(null); $encoder3 = $this->container->get('security.password_encoder'); $password3 = $encoder3->encodePassword($user3, 'slower'); $user3->setPassword($password3); $manager->persist($user3); $manager->flush(); $roleAdmin = new Role(); $roleAdmin->setRole('ROLE_ADMIN'); $roleAdmin->addUser($user); $roleAdmin->addUser($user2); $roleAdmin->addUser($user3); $manager->persist($roleAdmin); $roleTeacher = new Role(); $roleTeacher->setRole('ROLE_TEACHER'); $roleTeacher->addUser($user); $roleTeacher->addUser($user2); $roleTeacher->addUser($user3); $manager->persist($roleTeacher); $roleUser = new Role(); $roleUser->setRole('ROLE_USER'); $roleUser->addUser($user); $roleUser->addUser($user2); $roleUser->addUser($user3); $manager->persist($roleUser); $user->addRole($roleAdmin); $user->addRole($roleTeacher); $user->addRole($roleUser); $user2->addRole($roleAdmin); $user2->addRole($roleTeacher); $user2->addRole($roleUser); $user3->addRole($roleTeacher); $user3->addRole($roleUser); $manager->flush(); }