Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8950203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:24:04+00:00 2026-06-15T13:24:04+00:00

I am implementing a dialog for my login form in symfony2, it works well

  • 0

I am implementing a dialog for my login form in symfony2, it works well except I would want to handle the return with some more logic, now I don’t know how to do that since the firewall configuration picks up the login submission.

What happens is that if login failed, the html of my dialog is replaced with the new html returned by the login controller, this is all fine.
But if a successful login attempt occurs, the html of my login dialog is replaced with my entire site (since a successful symfony2 login will redirect to the start page…).

In flat PHP I would add this to the login controller

if (login_successful) {
  return "success";
}

and in my dialog function put

if (returned_data == "success") {
  refresh_page(); // or location.href('something')
}
else
{
  // replace dialog_html with the returned html
}

But as I look to the action taking care of the login form submission i FOS user bundle, this is what I find

public function checkAction()
{
    throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
}

So I realize this is all taken care of behind the scenes in symfony2, can I even get at this then?

Actual sample code (JS)…

function submitFormWithAjax(form) {
  form = $(form);
  $.ajax({
    url: form.attr('action'),
    data: form.serialize(),
    type: (form.attr('method')),
    dataType: 'html',
    success: function(data) {
        if (data == 'success') {
            //Success-token is passed, so reload page (will close dialog and load the logged-in start screen since user is now fully authenticated
            location.reload();
        }
        else {
            //Form is returned, probably with errors, so let user try again...
            $('#formDialog').html(data);
        }
      }
  });
  return false;
} 

and the form…

<form action="{{ path("fos_user_security_check") }}" method="post" id="login-form">
    <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />

    <TABLE>
        <TR>
            <TD><label for="username">Login</label></TD>
            <TD><input type="text" placeholder="användare" id="username" name="_username" value="{{ last_username }}" /></TD>
        </TR>
        <TR>
            <TD><label for="password">Lösenord</label></TD>
            <TD><input type="password" placeholder="lösenord" id="password" name="_password" /></TD>
        </TR>
        <TR>
            <TD><label for="remember_me">Kom ihåg mig</label></TD>
            <TD><input type="checkbox" id="remember_me" name="_remember_me" value="on" /></TD>
        </TR>
        <!--
        <TR>
            <TD></TD>
            <TD align="right"><input type="submit" id="_submit" name="_submit" value="Logga in" /></TD>
        </TR>
        -->
    </TABLE>

</form>

As per m2mdas suggestion below, I now have these set up:

config.yml

#My services
services:
    my.authentication.success_handler:
        class:     Hemekonomi\UserBundle\AuthenticationSuccessHandler
        parent:    security.authentication.success_handler  

my userbundle now has this class

<?php
namespace MyApp\UserBundle;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler
{
   public function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        if(true === $request->isXmlHttpRequest()) {
            return new Response("success");
        }

        //default redirect operation.
        return parent::onAuthenticationSuccess($request, $token);
    }

}

… and the security.yml has…

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            success_handler: my.authentication.success_handler
        logout:       true
        anonymous:    true

The error I get is this

RuntimeException: The parent definition "security.authentication.success_handler" defined for definition "my.authentication.success_handler" does not exist.

Could it have something to do with formatting, is it different in xml/yml? I am no expert in either so…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:24:05+00:00Added an answer on June 15, 2026 at 1:24 pm

    I ended up using this solution (thanks to m2mdas & http://blog.alterphp.com/2011/10/set-up-authenticationsuccesshandler.html)

    config.yml

    #My services
    parameters:
        security.authentication.success_handler.class: MyApp\UserBundle\Resources\AuthenticationSuccessHandler
    
    services:
        security.authentication.success_handler:
            class: %security.authentication.success_handler.class%
            public: false
            arguments:  ['@router', '@security.user.entity_manager']
    

    security.wml

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
                success_handler: security.authentication.success_handler
            logout:       true
            anonymous:    true
    

    successhandler (including slightly more functionality than what I asked for, might use this later on):

    <?php
    
    namespace MyApp\UserBundle\Resources;
    
    use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
    use Symfony\Component\HttpFoundation\RedirectResponse;
    use Symfony\Component\Routing\RouterInterface;
    use Doctrine\ORM\EntityManager;
    
    
    /**
     * Custom authentication success handler
     */
    class AuthenticationSuccessHandler implements AuthenticationSuccessHandlerInterface
    {
    
       private $router;
       private $em;
    
       /**
        * Constructor
        * @param RouterInterface   $router
        * @param EntityManager     $em
        */
       public function __construct(RouterInterface $router, EntityManager $em)
       {
          $this->router = $router;
          $this->em = $em;
       }
    
    
       function onAuthenticationSuccess(Request $request, TokenInterface $token)
       {
    
            if(true === $request->isXmlHttpRequest()) {
                return new Response("success");
            }
    
            //default redirect operation.
            $uri = $this->router->generate('MyAppSkrivbordBundle_homepage');
            return new RedirectResponse($uri);
    
    
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing a custom dialog to form an about screen with a simple
I am implementing an application managed login mechanism using some primefaces components. I successfully
I'm having a problem implementing the feed dialog function of Facebook within my canvas
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I'm creating a singleton to access all Facebook methods and I want to handle
I'm implementing some dialogs that need a common poll to get fresh values from
I'm just starting to mess with bindings. I've started implementing a preference dialog, binding
Question Is it possible to create a second Preference Dialog that can take some
I'm implementing Simplemodal in an application of mine using this code: $(.dialog-link).live('click', function(e) {
I was implementing a jqueryui modal dialog box and a related blog showed a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.