I am using FSOUserBundle and I want to override loginAction, I used this method:
namespace PjDZ\UserBundle\Controller;
use FOS\UserBundle\Controller\SecurityController as BaseController;
class SecurityController extends BaseController {
public function loginAction(\Symfony\Component\HttpFoundation\Request $request)
{
/** @var $session \Symfony\Component\HttpFoundation\Session\Session */
$session = $request->getSession();
// 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->has('form.csrf_provider')
? $this->container->get('form.csrf_provider')->generateCsrfToken('authenticate')
: null;
return $this->renderLogin(array(
'last_username' => $lastUsername,
'error' => $error,
'csrf_token' => $csrfToken,
));
}
}
but when I try to show /login page I get a blank page, any idea ?!!. forgive my bad english.
In Symfony version 3.3 and Fosuserbundle version 2.1.0, the above code will not work anymore until adding lines in config.yml:
services:
fos_user.security.controller:
class: MAIN\MAINFOSUserBundle\Controller\SecurityController
fos_user.resetting.controller:
class: MAIN\MAINFOSUserBundle\Controller\ResettingController
fos_user.profile.controller:
class: MAIN\MAINFOSUserBundle\Controller\ProfileController
fos_user.change_password.controller:
class: MAIN\MAINFOSUserBundle\Controller\ChangePasswordController
This is mainly because I keep friendsofsymfony up to date in composer.json
"friendsofsymfony/user-bundle": "~2.0@dev"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With