1

I implemented ajax login with Symfony2 and FOSUser bundle on my project so that users can login through a modal window (using AJAX and building my own handlers).

I now want to do the same thing but for registration. I want new users to register through a modal window and fire the registration handler through AJAX.

I cannot find a Registration handler to inherit from... Is this possbile? Any ideas?

Thanks

Anto
  • 41
  • 2
  • What is the question here? What "handler" are you looking for? Please provide some more information. 90% of the registration process in FOSUserBundle takes place in the [RegistrationController](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Controller/RegistrationController.php). – Nicolai Fröhlich Jan 21 '14 at 20:27
  • Hi nifr, the question is how can I handle user registration through a modal form? Is this possible in any way? For the login I followed this http://stackoverflow.com/questions/8607212/symfony2-ajax-login and it works – Anto Jan 21 '14 at 20:29

1 Answers1

0

You have to implement an authentication handler class witch redirect you where you want in case of authentication success.

services.yml

parameters:
    authentication_handler_class: Namespace\authenticationHandlerClass

services:
    authentication_handler:
        class:  %authentication_handler_class%
        arguments:  [@router]
        tags:
            - { name: 'monolog.logger', channel: 'security' }

authenticationHandlerClass

<?php

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;

class AuthenticationHandler implements AuthenticationSuccessHandlerInterface
{
    private $router;

    public function __construct(Router $router)
    {
        $this->router = $router;
    }

    public function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        $url = $this->router->generate('nameofmyroute');
        return new RedirectResponse($url);
    }
}
pCyril
  • 134
  • 1
  • 3