当前位置: 首页>>代码示例>>PHP>>正文


PHP User::getRoles方法代码示例

本文整理汇总了PHP中AppBundle\Entity\User::getRoles方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getRoles方法的具体用法?PHP User::getRoles怎么用?PHP User::getRoles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AppBundle\Entity\User的用法示例。


在下文中一共展示了User::getRoles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testFindAllUsersByDepartmentAndRoles

 public function testFindAllUsersByDepartmentAndRoles()
 {
     $this->users = $this->em->getRepository('AppBundle:User')->findAllUsersByDepartmentAndRoles(1, $this->em->getRepository('AppBundle:Role')->findOneByRole('ROLE_USER'));
     foreach ($this->users as $this->user) {
         $this->assertEquals(1, $this->user->getFieldOfStudy()->getDepartment()->getId());
         $this->assertContains(toArray('ROLE_USER'), $this->user->getRoles());
     }
 }
开发者ID:vegardbb,项目名称:webpage,代码行数:8,代码来源:UserRepositoryFunctionalTest.php

示例2: isGranted

 /**
  * Perform a single access check operation on a given attribute, object and (optionally) user
  * It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass
  * $user can be one of the following:
  *   a UserInterface object (fully authenticated user)
  *   a string               (anonymously authenticated user)
  *
  * @param string $attribute
  * @param User $object
  * @param UserInterface|string $user
  *
  * @return bool
  */
 protected function isGranted($attribute, $object, $user = null)
 {
     //Falta sacar el ROL de cada usuario
     if ($object->getRoles() == User::ROLE_DEFAULT) {
         dump($object->getRoles());
         return false;
     }
     return true;
 }
开发者ID:aulasoftwarelibre,项目名称:fastconfer,代码行数:22,代码来源:EditConferenceChairman.php

示例3: testRoles

 public function testRoles()
 {
     $user = new User();
     $this->assertTrue(in_array(User::$ROLE_USER, $user->getRoles()));
     $user->addRole(User::$ROLE_ADMIN);
     $this->assertTrue(in_array(User::$ROLE_USER, $user->getRoles()));
     $this->assertTrue(in_array(User::$ROLE_ADMIN, $user->getRoles()));
     $user->removeRole(User::$ROLE_ADMIN);
     $this->assertFalse(in_array(User::$ROLE_ADMIN, $user->getRoles()));
 }
开发者ID:Pamoi,项目名称:photo-gallery-api,代码行数:10,代码来源:UserTest.php

示例4: getUser

 public function getUser($authorizationCode, UserProviderInterface $userProvider)
 {
     $provider = $this->getFacebookOAuthProvider();
     try {
         // the credentials are really the access token
         $accessToken = $provider->getAccessToken('authorization_code', ['code' => $authorizationCode]);
     } catch (IdentityProviderException $ex) {
         $response = $e->getResponseBody();
         $errorCode = $response['error']['code'];
         $message = $response['error']['message'];
         //var_dump($response);
         //TODO throw a custom error to handle ???
     }
     $fbUser = $provider->getResourceOwner($accessToken);
     $email = $fbUser->getEmail();
     $em = $this->container->get('doctrine')->getManager();
     $user = $em->getRepository('AppBundle:User')->findOneBy(['email' => $email]);
     //If there is no user, we need to create one
     if (!$user) {
         $user = new User();
         $user->setUsername($email);
         $user->setEmail($email);
         //Set to unencoded password.
         //Since passwords are encode when checked, users should not be able to login using it
         $user->setPassword('FACEBOOK LOGIN');
         //Make sure that a user has at least the role of ROLE_USER when created
         $roles = $user->getRoles();
         $user->setRoles($roles);
     }
     $user->setFacebookId($fbUser->getId());
     $em->persist($user);
     $em->flush();
     return $user;
 }
开发者ID:TomasVotruba,项目名称:symfony-guard-project,代码行数:34,代码来源:FacebookAuthenticator.php

示例5: authenticate

 /**
  * 认证用户
  */
 public function authenticate(User $user, $providerKey)
 {
     $authenticationToken = new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
     $authenticationEvent = new InteractiveLoginEvent($this->request, $authenticationToken);
     $this->tokenStorage->setToken($authenticationToken);
     $this->dispatcher->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $authenticationEvent);
 }
开发者ID:timy-life,项目名称:segments,代码行数:10,代码来源:SymfonyAuthenticationService.php

示例6: authenticateUser

 private function authenticateUser(User $user)
 {
     $providerKey = 'frontend_area';
     // Firewall name
     $token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles());
     $this->container->get('security.token_storage')->setToken($token);
 }
开发者ID:Wolframcheg,项目名称:symfonyblog,代码行数:7,代码来源:AuthController.php

示例7: loginUser

 /**
  * @param User $user
  */
 protected function loginUser(User $user)
 {
     $security = $this->getSecurity();
     $providerKey = $this->container->getParameter('fos_user.firewall_name');
     $roles = $user->getRoles();
     $token = new UsernamePasswordToken($user, null, $providerKey, $roles);
     $security->setToken($token);
 }
开发者ID:samisalami,项目名称:xenobladex-org,代码行数:11,代码来源:UserController.php

示例8: getUser

 private function getUser($username)
 {
     $user = $this->getDoctrine()->getRepository('AppBundle:User')->findOneBy(['username' => $username]);
     if (!$user) {
         $user = new User($username, 'password');
     }
     $roles = $user->getRoles();
     foreach (['ROLE_USER', 'ROLE_API'] as $role) {
         if (!in_array($role, $roles)) {
             $roles[] = $role;
         }
     }
     $user->setRoles($roles);
     $manager = $this->getDoctrine()->getManager();
     $manager->persist($user);
     $manager->flush();
     return $user;
 }
开发者ID:drymek,项目名称:fcs-backend,代码行数:18,代码来源:FeatureContext.php

示例9: userExistsWith

 /**
  * @Given /^User "([^"]*)" exists with:$/
  */
 public function userExistsWith($username, TableNode $table)
 {
     $entity = new User($username, 'password');
     foreach ($table->getColumnsHash() as $row) {
         $value = $row['Value'];
         if ('Roles' === $row['Property']) {
             $roles = $entity->getRoles();
             if (!in_array($value, $roles)) {
                 $roles[] = $value;
             }
             $entity->setRoles($roles);
             continue;
         }
         $setter = 'set' . $row['Property'];
         $entity->{$setter}($value);
     }
     $this->getParameterBag()->set('user', $entity);
     $em = $this->getEntityManager();
     $em->persist($entity);
     $em->flush();
 }
开发者ID:drymek,项目名称:fcs-backend,代码行数:24,代码来源:DatabaseContext.php

示例10: getRoles

 /**
  * {@inheritDoc}
  */
 public function getRoles()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getRoles', []);
     return parent::getRoles();
 }
开发者ID:reathh,项目名称:MotikarqSystem,代码行数:8,代码来源:__CG__AppBundleEntityUser.php

示例11: should_add_user_role_when_confirmed

 /**
  * @test
  */
 public function should_add_user_role_when_confirmed()
 {
     $user = new User();
     $user->confirm();
     $this->assertSame(['ROLE_USER'], $user->getRoles());
 }
开发者ID:vaidasif,项目名称:symfony-force,代码行数:9,代码来源:UserTest.php

示例12: determineTheBiggestRole

 /**
  * @param User $user
  * @return \AppBundle\Entity\Role|null
  */
 private function determineTheBiggestRole(User $user)
 {
     $biggestRole = null;
     foreach ($user->getRoles() as $role) {
         if ($role->getRole() == UserService::ROLE_ADMIN) {
             $biggestRole = $role;
             break;
         }
         if ($role->getRole() == UserService::ROLE_TEACHER) {
             $biggestRole = $role;
         }
     }
     return $biggestRole;
 }
开发者ID:Gardax,项目名称:studentsSystem,代码行数:18,代码来源:UserModel.php

示例13: loginAction

 /**
  * @Route("/login/{id}", name="login")
  * @Method("GET")
  * @Template
  */
 public function loginAction(User $user)
 {
     $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
     $this->get('security.context')->setToken($token);
     return $this->redirect($this->generateUrl('projects'));
 }
开发者ID:vytautas-k,项目名称:DataDogAuditBundle,代码行数:11,代码来源:UserController.php

示例14: testAddRole

 public function testAddRole()
 {
     // new entity
     $user = new User();
     // New dummy entity
     $role1 = new Role();
     $role1->setName("role1");
     // Use the addRole method
     $user->addRole($role1);
     // Roles is stored in an array
     $roles = $user->getRoles();
     // Loop through the array and check for matches
     foreach ($roles as $role) {
         if ($role1 == $role) {
             // Assert the result
             $this->assertEquals($role1, $role);
         }
     }
 }
开发者ID:vegardbb,项目名称:webpage,代码行数:19,代码来源:UserEntityUnitTest.php

示例15: loginUser

 /**
  * Logs this user into the system
  *
  * @param User $user
  */
 public function loginUser(User $user)
 {
     $token = new UsernamePasswordToken($user, $user->getPassword(), 'main', $user->getRoles());
     $this->container->get('security.token_storage')->setToken($token);
 }
开发者ID:zcichanski,项目名称:symfony2-rest,代码行数:10,代码来源:BaseController.php


注:本文中的AppBundle\Entity\User::getRoles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。