當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。