對不起,我的英文不好的錯誤,但您的解決方案可能是:
聲明兩個服務,像這樣的應用程序/配置/服務.yml或一些其它service.yml任何束的內部(的appbundle例如):
app_user_security.component.authentication.handler.login_success_handler:
class: AdminBundle\Component\Authentication\Handler\LoginSuccessHandler
arguments: [@router, @security.context]
tags:
- { name: 'monolog.logger', channel: 'security' }
app_user_security.component.authentication.handler.logout_success_handler:
class: AdminBundle\Component\Authentication\Handler\LogoutSuccessHandler
arguments: [@router]
tags:
- { name: 'monolog.logger', channel: 'security' }
接着創建兩個類是這樣的:
<?php
/**
* Handler for users Login
*/
namespace AdminBundle\Component\Authentication\Handler;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use BeSimple\I18nRoutingBundle\Routing\Router;
class LoginSuccessHandler implements AuthenticationSuccessHandlerInterface {
protected $router;
protected $security;
function __construct(Router $router, SecurityContext $security)
{
$this->router = $router;
$this->security = $security;
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
$session = $request->getSession();
$obj = array();
$obj['name'] = $token->getUser()->__toString();
$obj['username'] = $token->getUsername();
$session->set('last_login_user', $obj);
if ($this->security->isGranted('ROLE_SUPER_ADMIN') || $this->security->isGranted('ROLE_ADMINISTRADOR'))
{
$referer_url = $this->router->generate('admin_dashboard');
}
elseif($this->security->isGranted('ROLE_USUARIO') || $this->security->isGranted('ROLE_USUARIO_SOCIAL')) {
$referer_url = $this->router->generate('app_frontend_dashboard', array(
//'slug' => $token->getUser()->getSlug()
));
} else {
$referer_url = $this->router->generate('app_frontend_dashboard');
}
$cookie = new Cookie('last_login_user', serialize($token->getUser()), time()+(3600*48));
$response = new RedirectResponse($referer_url);
$response->headers->setCookie($cookie);
return $response;
}
}
這:
<?php
/**
* Handler for logout...
*/
namespace AdminBundle\Component\Authentication\Handler;
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use BeSimple\I18nRoutingBundle\Routing\Router;
class LogoutSuccessHandler implements LogoutSuccessHandlerInterface {
protected $router;
public function __construct(Router $router)
{
$this->router = $router;
}
public function onLogoutSuccess(Request $request)
{
// redirect the user to where they were before the login process begun.
//$referer_url = $request->headers->get('referer');
//$response = new RedirectResponse($referer_url);
$referer_url = $this->router->generate('app_frontend_homepage');
$response = new RedirectResponse($referer_url);
return $response;
}
}
好陸先生!
我解決任何用戶提供的問題鏈供應商是這樣的:
//security.yml
security:
encoders:
#FOS\UserBundle\Model\UserInterface: bcrypt
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMINISTRADOR: [ROLE_USUARIO, ROLE_USUARIO_SOCIAL]
ROLE_SUPER_ADMINISTRADOR: ROLE_ADMINISTRADOR
# http://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
chain_provider:
chain:
providers: [in_memory, fos_userbundle, user_db_username, user_db_email]
in_memory:
memory: ~
fos_userbundle:
id: fos_user.user_provider.username_email
user_db_username:
entity: { class: AdminBundle\Entity\UsuarioBase, property: username }
user_db_email:
entity: { class: AdminBundle\Entity\UsuarioBase, property: email }
我覺得剛纔爲什麼有FOSUserBundle和PUXMultiuserBundle不相容一定程度上,一些認爲前工作時間,現在是碎米!
我打算,並希望它會好的:D,但我認爲這是問題的基礎,每個人都有一個小的差異,使現成的捆綁麻煩。 – alexseif