Skip to content

Instantly share code, notes, and snippets.

@alexdumont
Last active August 29, 2015 14:20
Show Gist options
  • Save alexdumont/5c5ee873a0de7375f221 to your computer and use it in GitHub Desktop.
Save alexdumont/5c5ee873a0de7375f221 to your computer and use it in GitHub Desktop.
A simple code for a form login by firewall in FOSUserBundle (Symfony2). One concept : overwriting.
<?php
namespace Pr3ss\UserBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use FOS\UserBundle\Controller\SecurityController as BaseController;
class SecurityController extends BaseController {
protected function renderLogin(array $data) {
// get target path
if(strpos($this->container->get('request')->get('_route'), 'backend') !== false) {
$template = 'Pr3ssUserBundle:Backend/Security:signin.html.twig';
} else {
$template = 'Pr3ssUserBundle:Frontend/Security:signin.html.twig';
}
return $this->container->get('templating')->renderResponse($template, $data);
}
}
# routing.yml
backend_login:
pattern: /backend/login
defaults: { _controller: FOSUserBundle:Security:login }
backend_login_check:
pattern: /backend/login_check
defaults: { _controller: FOSUserBundle:Security:check }
backend_logout:
pattern: /backend/logout
defaults: { _controller: FOSUserBundle:Security:logout }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment