Scandal at the tavern: a customer found the /kitchen/new-dish page and added a “Pippin's Stew, free of charge” to the menu. The kitchen must be closed to the public: only Bruna gets in.
Symfony's Security component is built around a firewall (who are you?) and access rules (are you allowed?).
Your mission
In config/packages/security.yaml:
- Declare an in-memory user:
bruna, roleROLE_CUISINIER(cuisinier= cook), passwordcauldron… hashed, never in plain text. The console computes it for you:security:hash-password cauldron. - In the
mainfirewall, enable form login (pageapp_connexion,connexion= login) and logout (routeapp_deconnexion, back to the home page). - Reserve everything starting with
/kitchenfor theROLE_CUISINIERrole.
In SecuriteController::connexion() (Securite = security), pass the last username entered and the last login error to the template (AuthenticationUtils service), as dernier_identifiant (last username) and erreur (error). The login page and the navigation (Log in / Log out) are ready.
Reminder
You don't write the code that checks the password: the firewall intercepts the form sent to check_path, compares the hashed password, opens the session, then sends you back where you were going.