本文整理汇总了PHP中FOS\UserBundle\Model\UserInterface::getRoles方法的典型用法代码示例。如果您正苦于以下问题:PHP UserInterface::getRoles方法的具体用法?PHP UserInterface::getRoles怎么用?PHP UserInterface::getRoles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FOS\UserBundle\Model\UserInterface
的用法示例。
在下文中一共展示了UserInterface::getRoles方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRedirectionUrl
/**
* {@inheritdoc}
*/
protected function getRedirectionUrl(UserInterface $user)
{
$rolesTab = $user->getRoles();
if (in_array('ROLE_ADMIN', $rolesTab, true) || in_array('ROLE_SUPER_ADMIN', $rolesTab, true)) {
return $this->container->get('router')->generate('sonata_admin_dashboard');
} else {
return $this->container->get('router')->generate('sonata_user_profile_show');
}
}
示例2: updateRoles
/**
*
*/
public function updateRoles(UserInterface $user)
{
$roles = $user->getRoles();
$roleRepository = $this->objectManager->getRepository('WeavingTheWebUserBundle:Role');
foreach ($roles as $role) {
$roleName = (string) $role;
$roleEntity = $roleRepository->findOneByRole($roleName);
$user->removeRole($role);
$user->addRole($roleEntity);
}
}
示例3: SamlUser
function it_load_user_by_username(SamlAuth $auth, UserInterface $user, UserManagerInterface $userManager)
{
$auth->getAttributes()->shouldBeCalled();
$auth->getUsername()->shouldBeCalled();
$auth->isAuthenticated()->shouldBeCalled();
$user->getUsername()->shouldBeCalled();
$user->getRoles()->shouldBeCalled();
$userManager->findUserByUsername(self::USERNAME)->shouldBeCalled();
$samlUser = new SamlUser('user@domain.com', ['ROLE_USER'], []);
$this->loadUserByUsername('user@domain.com')->shouldBeLike($samlUser);
}
示例4: createToken
protected function createToken($firewall, UserInterface $user)
{
return new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
}
示例5: userLoginAction
/**
* add the symfony-login "manually".
*
* use the symfony token-storage for the generated UsernamePasswordToken
* to access the (logged in) user later (e.g. to check for roles or permissions)
*
* the given $passwordHash must match the encrypted password in the user-object
*
* before and after the generation/setting of the token, the events "secotrust.user_login.before"
* and "secotrust.user_login.after" are called, if some EventListeners are configured
*
* @param \FOS\UserBundle\Model\UserInterface $user
* @param $passwordHash
*/
private function userLoginAction(\FOS\UserBundle\Model\UserInterface $user, $passwordHash)
{
// call the pre-login-event
$event = new Event();
$this->dispatcher->dispatch('secotrust.user_login.before', $event);
if ($user->getPassword() !== $passwordHash) {
// stop the login-action, when the password doesn't match
return;
}
$token = new UsernamePasswordToken($user, null, 'secured_area', $user->getRoles());
$this->token_storage->setToken($token);
// call the post-login-event
$event = new Event();
$this->dispatcher->dispatch('secotrust.user_login.after', $event);
}
示例6: authenticateUser
/**
* Authenticate a user with Symfony Security
*
* @param \FOS\UserBundle\Model\UserInterface $user
*/
protected function authenticateUser(UserInterface $user)
{
$providerKey = $this->container->getParameter('fos_user.firewall_name');
$token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles());
$this->container->get('security.context')->setToken($token);
}
示例7: authenticateUser
/**
* Authenticate a user with Symfony Security
*
* @param Boolean $reAuthenticate
* @return null
*/
protected function authenticateUser(UserInterface $user, $reAuthenticate = false)
{
$providerKey = $this->container->getParameter('fos_user.provider_key');
$token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles());
if (true === $reAuthenticate) {
$token->setAuthenticated(false);
}
$this->container->get('security.context')->setToken($token);
}