相关疑难解决方法(0)

Symfony2 AJAX登录

我有一个例子,我试图使用Symfony2和FOSUserBundle创建一个AJAX登录.我设置我自己success_handlerfailure_handlerform_login我的security.yml文件.

这是班级:

class AjaxAuthenticationListener implements AuthenticationSuccessHandlerInterface, AuthenticationFailureHandlerInterface
{  
    /**
     * This is called when an interactive authentication attempt succeeds. This
     * is called by authentication listeners inheriting from
     * AbstractAuthenticationListener.
     *
     * @see \Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener
     * @param Request        $request
     * @param TokenInterface $token
     * @return Response the response to return
     */
    public function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        if ($request->isXmlHttpRequest()) {
            $result = array('success' => true);
            $response = new Response(json_encode($result));
            $response->headers->set('Content-Type', 'application/json');
            return …
Run Code Online (Sandbox Code Playgroud)

php symfony fosuserbundle

43
推荐指数
2
解决办法
3万
查看次数

如何在Symfony 2中的login_check之后禁用重定向

我需要在登录检查后禁用重定向,因为我只需要获取登录成功与否.提交/ login_check后url给我正确的数据,但保持重定向到/ login(失败时).
之后/ login是空白的.
我正在尝试使用extjs 4设置登录表单,所以我需要通过ajax post请求来验证.login_check应该进行身份验证,创建用户会话并返回它是成功还是失败,但不在任何地方转发.

我的login.html.twig看起来像:

{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
    { success:true }
{% else %}
    { success: false }
{% endif %}
Run Code Online (Sandbox Code Playgroud)

并在security.yml:

firewalls:
    main:
        form_login:
            provider: fos_userbundle
            failure_path:  null
            failure_forward: false
Run Code Online (Sandbox Code Playgroud)

php symfony

31
推荐指数
1
解决办法
2万
查看次数

标签 统计

php ×2

symfony ×2

fosuserbundle ×1