]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Acme/DemoBundle/Controller/SecuredController.php
symfony is there
[github/wallabag/wallabag.git] / src / Acme / DemoBundle / Controller / SecuredController.php
1 <?php
2
3 namespace Acme\DemoBundle\Controller;
4
5 use Symfony\Component\HttpFoundation\Request;
6 use Symfony\Component\Security\Core\SecurityContext;
7 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
10 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
11
12 /**
13 * @Route("/demo/secured")
14 */
15 class SecuredController extends Controller
16 {
17 /**
18 * @Route("/login", name="_demo_login")
19 * @Template()
20 */
21 public function loginAction(Request $request)
22 {
23 if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
24 $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
25 } else {
26 $error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
27 }
28
29 return array(
30 'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME),
31 'error' => $error,
32 );
33 }
34
35 /**
36 * @Route("/login_check", name="_demo_security_check")
37 */
38 public function securityCheckAction()
39 {
40 // The security layer will intercept this request
41 }
42
43 /**
44 * @Route("/logout", name="_demo_logout")
45 */
46 public function logoutAction()
47 {
48 // The security layer will intercept this request
49 }
50
51 /**
52 * @Route("/hello", defaults={"name"="World"}),
53 * @Route("/hello/{name}", name="_demo_secured_hello")
54 * @Template()
55 */
56 public function helloAction($name)
57 {
58 return array('name' => $name);
59 }
60
61 /**
62 * @Route("/hello/admin/{name}", name="_demo_secured_hello_admin")
63 * @Security("is_granted('ROLE_ADMIN')")
64 * @Template()
65 */
66 public function helloadminAction($name)
67 {
68 return array('name' => $name);
69 }
70 }