本文整理汇总了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());
}
}
示例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;
}
示例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()));
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例10: getRoles
/**
* {@inheritDoc}
*/
public function getRoles()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getRoles', []);
return parent::getRoles();
}
示例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());
}
示例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;
}
示例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'));
}
示例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);
}
}
}
示例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);
}