Php 如何使用security.yml中的PUGXMultiUserBundle设置防火墙
我刚开始使用PUGXMultiUserBundle 我希望系统中有2个用户(管理、客户端) 现在我想有单独的管理面板和不同的重定向后成功登录,注册等 难道我不能基于用户识别在security.yml中设置防火墙吗 现在,我按照说明完成了注册表单的构建,我的用户被分离了。 注册完成后,我在确认的url上得到一个错误Php 如何使用security.yml中的PUGXMultiUserBundle设置防火墙,php,symfony,Php,Symfony,我刚开始使用PUGXMultiUserBundle 我希望系统中有2个用户(管理、客户端) 现在我想有单独的管理面板和不同的重定向后成功登录,注册等 难道我不能基于用户识别在security.yml中设置防火墙吗 现在,我按照说明完成了注册表单的构建,我的用户被分离了。 注册完成后,我在确认的url上得到一个错误 没有用户“AppBundle\Entity\CabAgencyUser”的用户提供程序。很抱歉我的英语很差,但您的解决方案可能是: 在app/config/services.yml或任
没有用户“AppBundle\Entity\CabAgencyUser”的用户提供程序。
很抱歉我的英语很差,但您的解决方案可能是:
在app/config/services.yml或任何捆绑包(例如AppBundle)中的某个其他service.yml中声明两个类似的服务:
接下来创建两个类,如下所示:
<?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;
}
}
//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,但我认为这是问题的基础,每个人都有微小的差异,这使得一个现成的包成为一个麻烦。
<?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 }