forked from symfony/demo
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSecurityController.php
93 lines (82 loc) · 2.74 KB
/
SecurityController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
/**
* Controller used to manage the application security.
* See http://symfony.com/doc/current/cookbook/security/form_login_setup.html.
*
* @author Ryan Weaver <weaverryan@gmail.com>
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*/
class SecurityController extends Controller
{
/**
* @Route("/login", name="security_login_form")
*/
public function loginAction()
{
$helper = $this->get('security.authentication_utils');
return $this->render('security/login.html.twig', array(
// last username entered by the user (if any)
'last_username' => $helper->getLastUsername(),
// last authentication error (if any)
'error' => $helper->getLastAuthenticationError(),
));
}
/**
* @Route("/login/auto/{username}")
*/
public function autoLogin($username, Request $request)
{
$user = $this->getDoctrine()
->getRepository('AppBundle:User')
->findOneBy(['username' => $username]);
if (!$user) {
throw $this->createNotFoundException('No user!');
}
$firewallKey = 'secured_area';
$authenticator = $this->container->get('app.form_login_authenticator');
$guardHandler = $this->container->get('security.authentication.guard_handler');
$successResponse = $guardHandler->authenticateUserAndHandleSuccess(
$user,
$request,
$authenticator,
$firewallKey
);
return $successResponse;
}
/**
* This is the route the login form submits to.
*
* But, this will never be executed. Symfony will intercept this first
* and handle the login automatically. See form_login in app/config/security.yml
*
* @Route("/login_check", name="security_login_check")
*/
public function loginCheckAction()
{
throw new \Exception('This should never be reached!');
}
/**
* This is the route the user can use to logout.
*
* But, this will never be executed. Symfony will intercept this first
* and handle the logout automatically. See logout in app/config/security.yml
*
* @Route("/logout", name="security_logout")
*/
public function logoutAction()
{
throw new \Exception('This should never be reached!');
}
}