Here's my security.yml for user login:
user_secured_area:
pattern: /*
anonymous: ~
provider: user
form_login:
check_path: /login_check
login_path: /login
use_referer: true
username_parameter: _email
logout:
path: logout
target: /
I've checked the profiler for HTTP_REFERRER and i've got the correct referer. However upon login, it is redirected to the root URL and not the referer URL. Any idea on this or have i missed out something?
The controller:
public function indexAction(Request $request){
$session = $request->getSession();
//get login error
if($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)){
$error = $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR);
}
else if(null!==$session && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)){
$error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR);
$session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
}
else{
$error = "";
}
//repopulate username
$lastEmail = (null === $session) ? '' : $session->get(SecurityContextInterface::LAST_USERNAME); // a ? true : false
return $this->render('BazaarBundle:Login:login.html.twig', array('last_email' => $lastEmail, 'error' => $error));
}
The twig:
<form action="{{ path('login_check') }}" method="post">
<label for="email">Email:</label>
<input type="text" id="email" name="_email" value="{{ last_email }}" />
<label for="password">Password:</label>
<input type="password" id="password" name="_password" />
<button type="submit">login</button>