diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index 7853e9e..e914da4 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -1,7 +1,8 @@ # see https://symfony.com/doc/current/reference/configuration/framework.html framework: secret: '%env(APP_SECRET)%' - #csrf_protection: true + ide: 'myide://open?url=file://%%f&line=%%l' + csrf_protection: true http_method_override: false # Enables session support. Note that the session will ONLY be started if you read or write from it. @@ -22,3 +23,4 @@ when@test: test: true session: storage_factory_id: session.storage.factory.mock_file + diff --git a/config/packages/security.yaml b/config/packages/security.yaml index fbfb8ed..ee074d8 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -1,43 +1,52 @@ security: - # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords - password_hashers: - Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' - # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider - providers: - # used to reload user from session & other features (e.g. switch_user) - app_user_provider: - entity: - class: App\Entity\User - property: email - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - lazy: true - provider: app_user_provider + # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords + password_hashers: + Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' + # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider + providers: + # used to reload user from session & other features (e.g. switch_user) + app_user_provider: + entity: + class: App\Entity\User + property: email + firewalls: + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + main: + lazy: true + provider: app_user_provider - # activate different ways to authenticate - # https://symfony.com/doc/current/security.html#the-firewall - # https://symfony.com/doc/current/security/impersonating_user.html - # switch_user: true +# activate different ways to authenticate +# https://symfony.com/doc/current/security.html#the-firewall - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } +# https://symfony.com/doc/current/security/impersonating_user.html + switch_user: true + form_login: + login_path: app_login + check_path: app_login + enable_csrf: true + logout: + path: app_logout + # where to redirect after logout + # target: app_any_route + + # Easy way to control access for large sections of your site + # Note: Only the *first* access control that matches will be used + access_control: + - { path: ^/admin, roles: ROLE_ADMIN } + - { path: ^/profile, roles: ROLE_USER } when@test: - security: - password_hashers: - # By default, password hashers are resource intensive and take time. This is - # important to generate secure password hashes. In tests however, secure hashes - # are not important, waste resources and increase test times. The following - # reduces the work factor to the lowest possible values. - Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: - algorithm: auto - cost: 4 # Lowest possible value for bcrypt - time_cost: 3 # Lowest possible value for argon - memory_cost: 10 # Lowest possible value for argon + security: + password_hashers: + # By default, password hashers are resource intensive and take time. This is + # important to generate secure password hashes. In tests however, secure hashes + # are not important, waste resources and increase test times. The following + # reduces the work factor to the lowest possible values. + Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: + algorithm: auto + cost: 4 # Lowest possible value for bcrypt + time_cost: 3 # Lowest possible value for argon + memory_cost: 10 # Lowest possible value for argon diff --git a/src/Controller/AccountController.php b/src/Controller/AccountController.php new file mode 100644 index 0000000..371f016 --- /dev/null +++ b/src/Controller/AccountController.php @@ -0,0 +1,18 @@ +render('account/index.html.twig', [ + 'controller_name' => 'AccountController', + ]); + } +} diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php new file mode 100644 index 0000000..f0b3d4e --- /dev/null +++ b/src/Controller/IndexController.php @@ -0,0 +1,18 @@ +render('index/index.html.twig', [ + 'controller_name' => 'IndexController', + ]); + } +} diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php new file mode 100644 index 0000000..5e4022d --- /dev/null +++ b/src/Controller/SecurityController.php @@ -0,0 +1,32 @@ +getLastAuthenticationError(); + + // last username entered by the user + $lastUsername = $authenticationUtils->getLastUsername(); + + return $this->render('security/login.html.twig', [ + 'last_username' => $lastUsername, + 'error' => $error, + ]); + } + + #[Route(path: '/logout', name: 'app_logout')] + public function logout(): void + { + throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); + } +} diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index c788f46..86717f8 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -40,28 +40,4 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader $this->getEntityManager()->flush(); } -// /** -// * @return User[] Returns an array of User objects -// */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('u') -// ->andWhere('u.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('u.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } - -// public function findOneBySomeField($value): ?User -// { -// return $this->createQueryBuilder('u') -// ->andWhere('u.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } } diff --git a/templates/account/index.html.twig b/templates/account/index.html.twig new file mode 100644 index 0000000..f951c35 --- /dev/null +++ b/templates/account/index.html.twig @@ -0,0 +1,43 @@ +{% extends 'base.html.twig' %} + +{% block title %}Votre compte{% endblock %} + +{% block body %} + +
+
+ +

+ Mon compte +

+

+ Coucou! +

+ + Un menu +
    +
  • un choix
  • +
  • un autre
  • +
  • un bidule
  • +
+
+ +
+
+{% endblock body %} diff --git a/templates/account_nop/index.html.twig b/templates/account_nop/index.html.twig new file mode 100644 index 0000000..f951c35 --- /dev/null +++ b/templates/account_nop/index.html.twig @@ -0,0 +1,43 @@ +{% extends 'base.html.twig' %} + +{% block title %}Votre compte{% endblock %} + +{% block body %} + +
+
+ +

+ Mon compte +

+

+ Coucou! +

+ + Un menu +
    +
  • un choix
  • +
  • un autre
  • +
  • un bidule
  • +
+
+ +
+
+{% endblock body %} diff --git a/templates/base.html.twig b/templates/base.html.twig index d4f83f7..4f68c66 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -1,19 +1,23 @@ - - - - {% block title %}Welcome!{% endblock %} - - {# Run `composer require symfony/webpack-encore-bundle` to start using Symfony UX #} - {% block stylesheets %} - {{ encore_entry_link_tags('app') }} - {% endblock %} + + + + {% block title %}Bienvenu!{% endblock %} + + {# Run `composer require symfony/webpack-encore-bundle` to start using Symfony UX #} + {% block stylesheets %} + {{ encore_entry_link_tags('app') }} + {% endblock %} - {% block javascripts %} - {{ encore_entry_script_tags('app') }} - {% endblock %} - - + {% block javascripts %} + {{ encore_entry_script_tags('app') }} + {% endblock %} + + +
+ {% import 'nav' %} {% block body %}{% endblock %} - +
+ diff --git a/templates/common/nav.html.twig b/templates/common/nav.html.twig new file mode 100644 index 0000000..66df1cb --- /dev/null +++ b/templates/common/nav.html.twig @@ -0,0 +1,14 @@ + diff --git a/templates/index/index.html.twig b/templates/index/index.html.twig new file mode 100644 index 0000000..eb6bab5 --- /dev/null +++ b/templates/index/index.html.twig @@ -0,0 +1,20 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello IndexController!{% endblock %} + +{% block body %} + + +
+

Hello {{ controller_name }}! ✅

+ + This friendly message is coming from: + +
+{% endblock %} diff --git a/templates/security/login.html.twig b/templates/security/login.html.twig new file mode 100644 index 0000000..890c59f --- /dev/null +++ b/templates/security/login.html.twig @@ -0,0 +1,46 @@ +{% extends 'base.html.twig' %} + +{% block title %}Log in!{% endblock %} + +{% block body %} +
+ {% if error %} +
{{ error.messageKey|trans(error.messageData, 'security') }}
+ {% endif %} + + {% if app.user %} +
+ You are logged in as {{ app.user.userIdentifier }}, Logout +
+ {% endif %} + +

Please sign in

+ + + + + + + + {# + Uncomment this section and add a remember_me option below your firewall to activate remember me functionality. + See https://symfony.com/doc/current/security/remember_me.html + +
+ +
+ #} + {# + If you want to control the URL the user is redirected to on success + #} + + + +
+{% endblock %}