/
SecurityController.php
65 lines (55 loc) · 1.66 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
<?php
/*
*
* User: camm
*/
namespace MelbSymfony2\ForumExampleBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Security\Core\SecurityContext;
/**
*
* @author camm
*/
class SecurityController extends Controller
{
/**
* @Route("/", name="user_bar")
* @Template("MelbSymfony2ForumExampleBundle:Security:user-bar.html.twig")
*/
public function userBarAction() {
return array('user' => $this->get('security.context')->getToken()->getUser());
}
/**
* @Route("/session/login", name="login")
* @Template("MelbSymfony2ForumExampleBundle:Security:session-login.html.twig")
*
*/
public function loginAction()
{
// get the login error if there is one
if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
}
return array(
// last username entered by the user
'last_username' => $this->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
'error' => $error,
);
}
/**
* @Route("/session/logout", name="logout")
*/
public function logoutAction()
{
}
/**
* @Route("/session/login/check", name="login_check")
*/
public function loginCheckAction()
{
}
}