Skip to content

Symfony 7: Security

  • https://symfony.com/doc/current/security.html
composer require symfony/security-bundle

User

syc make:user --with-uuid
syc make:entity
# add email
 Next Steps:
   - Review your new App\Entity\User class.
   - Use make:entity to add more fields to your User entity and then run make:migration.
   - Create a way to authenticate! See https://symfony.com/doc/current/security.html
syc make:migration --formatted
syc doctrine:migrations:migrate

Registration

composer require symfonycasts/verify-email-bundle
syc make:registration-form
#  ! [NOTE] No authenticators found - so your user won't be automatically authenticated after registering.
 Next:
 1) Install some missing packages:
      composer require symfony/mailer
 2) In RegistrationController::verifyUserEmail():
    * Customize the last redirectToRoute() after a successful email verification.
    * Make sure you're rendering success flash messages or change the $this->addFlash() line.
 3) Review and customize the form, controller, and templates as needed.
 4) Run "symfony console make:migration" to generate a migration for the newly added User::isVerified property.

 Then open your browser, go to "/register" and enjoy your new form!

Login

syc make:security:form-login
#  "Next: Review and adapt the login template: security/login.html.twig to suit your needs."
# Then fix manually (code style, etc)

Firewall

Access Control (Authorization)

UPDATE user SET roles = '["ROLE_ADMIN"]' WHERE username = 'admin' LIMIT 1;