I installed FOSUserBundle, but my design requires that the login form appears in the Home Page, not a separate login page, but included in the Home Page that is controlled by my HomeBundle:Default:index.
So if you access a page that requires login you would be redirected to my Home Page, where my login form is.
In order to do this: I changed the vendor > friendsofsymfony > user-bundle > FOS > Resources > routing > security.xml
<route id="fos_user_security_login" pattern="/login"> <default key="_controller">FOSUserBundle:Security:login</default> </route>
To point to the Controller that shows my HomePage. This works (it shows my login page) but here comes the problem, when I try to login it never logs me in and instead it shows the same page. The name of the inputs are correct and also de "action", same values as the default login form.
If I use the login page by default it logs me in, so the db is ok. I tried to print the errors that the log in process might trow printing the $error that figures out this code:
$request = $this->container->get('request'); /* @var $request \Symfony\Component\HttpFoundation\Request / $session = $request->getSession(); / @var $session \Symfony\Component\HttpFoundation\Session */
// get the error if any (works with forward and redirect -- see below)
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} elseif (null !== $session && $session->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = '';
}
if ($error) {
// TODO: this is a potential security risk (see http://trac.symfony-project.org/ticket/9523)
$error = $error->getMessage();
}
// last username entered by the user
$lastUsername = (null === $session) ? '' : $session->get(SecurityContext::LAST_USERNAME);
$csrfToken = $this->container->get('form.csrf_provider')->generateCsrfToken('authenticate');
But it seems that there's no error.