From 0c689194a2ee65a31cee66d9a5ef4b8a3133a12d Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 6 Sep 2018 16:46:33 +0200 Subject: [PATCH] In between commit implementation securitycontroller --- application/config/packages/security.yaml | 5 ++- .../src/Controller/SecurityController.php | 31 +++++++++++++++++++ application/src/Controller/UserController.php | 12 +++---- .../Controller/UserControllerInterface.php | 3 +- .../src/Subscriber/UserMenuSubscriber.php | 2 +- application/templates/user/login.html.twig | 25 +++++++++------ 6 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 application/src/Controller/SecurityController.php diff --git a/application/config/packages/security.yaml b/application/config/packages/security.yaml index b1e3aba..f3ae882 100644 --- a/application/config/packages/security.yaml +++ b/application/config/packages/security.yaml @@ -8,13 +8,16 @@ security: entity: class: App\Entity\User property: username - in_memory: { memory: ~ } + #in_memory: { memory: ~ } firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false main: anonymous: true + form_login: + login_path: login + check_path: login # activate different ways to authenticate diff --git a/application/src/Controller/SecurityController.php b/application/src/Controller/SecurityController.php new file mode 100644 index 0000000..2b562cf --- /dev/null +++ b/application/src/Controller/SecurityController.php @@ -0,0 +1,31 @@ +getLastAuthenticationError(); + if ($error) { + $this->addFlash('notice', $error); + } + return $this->render("user/login.html.twig",[ + 'last_username'=>$authenticationUtils->getLastUsername(), + ]); + } +} + diff --git a/application/src/Controller/UserController.php b/application/src/Controller/UserController.php index aa09860..18aa3bb 100644 --- a/application/src/Controller/UserController.php +++ b/application/src/Controller/UserController.php @@ -4,6 +4,7 @@ namespace App\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; /** * @@ -12,7 +13,9 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; */ class UserController extends AbstractController implements UserControllerInterface { + /** + * * @Route("/user/logout", name="user_logout") */ public function logout(): Response @@ -21,14 +24,7 @@ class UserController extends AbstractController implements UserControllerInterfa } /** - * @Route("/user/login", name="user_login") - */ - public function login(): Response - { - return $this->render("user/login.html.twig"); - } - - /** + * * @Route("/user/register", name="user_register") */ public function register(): Response diff --git a/application/src/Controller/UserControllerInterface.php b/application/src/Controller/UserControllerInterface.php index 0640c32..d285b2f 100644 --- a/application/src/Controller/UserControllerInterface.php +++ b/application/src/Controller/UserControllerInterface.php @@ -2,6 +2,7 @@ namespace App\Controller; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; /** * @@ -12,7 +13,5 @@ interface UserControllerInterface { public function logout():Response; - public function login():Response; - public function register():Response; } diff --git a/application/src/Subscriber/UserMenuSubscriber.php b/application/src/Subscriber/UserMenuSubscriber.php index 42f614f..b327145 100644 --- a/application/src/Subscriber/UserMenuSubscriber.php +++ b/application/src/Subscriber/UserMenuSubscriber.php @@ -62,7 +62,7 @@ class UserMenuSubscriber implements EventSubscriberInterface $dropdown->addChild( 'login', [ - 'route' => 'user_login', + 'route' => 'login', 'attributes' => [ 'divider_append' => true, 'icon' => 'fas fa-sign-in-alt', diff --git a/application/templates/user/login.html.twig b/application/templates/user/login.html.twig index 6fad0ce..47b76f0 100644 --- a/application/templates/user/login.html.twig +++ b/application/templates/user/login.html.twig @@ -1,20 +1,25 @@ {% extends "frames/default.html.twig" %} {% block title %} -login +{% trans %}login{% endtrans %} {% endblock %} {% block content %} -

Login

-
+

+ {% trans %}login{% endtrans %} +

+
- +
- +
- +
{% endblock %}