public function authenticate()
{
// Do not redirect if authentication is successful
if (parent::authenticate()) {
return true;
}
$route = \System::getContainer()->get('request_stack')->getCurrentRequest()->attributes->get('_route');
if ($route == 'contao_backend_login') {
return false;
}
$parameters = array();
// Redirect to the last page visited upon login
if ($route == 'contao_backend' || $route == 'contao_backend_preview') {
$parameters['referer'] = base64_encode(\Environment::get('request'));
}
throw new RedirectResponseException(\System::getContainer()->get('router')->generate('contao_backend_login', $parameters, UrlGeneratorInterface::ABSOLUTE_URL));
}