diff --git a/Resources/doc/getting_started.md b/Resources/doc/getting_started.md index 516ab20..b3b4df5 100644 --- a/Resources/doc/getting_started.md +++ b/Resources/doc/getting_started.md @@ -16,16 +16,11 @@ composer require tilleuls/forgot-password-bundle Register this bundle in your kernel: ```php -// app/AppKernel.php -public function registerBundles() -{ - $bundles = [ - new CoopTilleuls\ForgotPasswordBundle\CoopTilleulsForgotPasswordBundle(), - // ... - ]; - +// config/bundles.php +return [ // ... -} + CoopTilleuls\ForgotPasswordBundle\CoopTilleulsForgotPasswordBundle::class => ['all' => true], +]; ``` ## Configuration @@ -35,10 +30,10 @@ public function registerBundles() Load routing: ```yml -# app/config/routing.yml +# config/routes/coop_tilleuls_forgot_password.yaml coop_tilleuls_forgot_password: - resource: '@CoopTilleulsForgotPasswordBundle/Resources/config/routing.xml' - prefix: '/forgot_password' + resource: "@CoopTilleulsForgotPasswordBundle/Resources/config/routing.xml" + prefix: /forgot_password ``` This provides 2 main routes: @@ -51,7 +46,8 @@ CoopTilleulsForgotPasswordBundle provides an abstract _mapped superclass_, you'l `PasswordToken` entity for your project: ```php -namespace AppBundle\Entity; +// src/Entity/PasswordToken.php +namespace App\Entity; use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; use Doctrine\ORM\Mapping as ORM; @@ -73,7 +69,7 @@ class PasswordToken extends AbstractPasswordToken /** * @var User * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User") + * @ORM\ManyToOne(targetEntity=User::class) * @ORM\JoinColumn(nullable=false) */ private $user; @@ -109,16 +105,23 @@ class PasswordToken extends AbstractPasswordToken Enable required configuration: ```yml -# app/config/config.yml +# config/packages/coop_tilleuls_forgot_password.yaml coop_tilleuls_forgot_password: - password_token_class: 'AppBundle\Entity\PasswordToken' - user_class: 'AppBundle\Entity\User' + password_token: + class: App\Entity\PasswordToken # required + expires_in: 1 day + user_field: user + serialization_groups: [] + user: + class: App\Entity\User # required + email_field: email + password_field: password ``` Update your security to allow anonymous users to reset their password: ```yml -# app/config/security.yml +# config/packages/security.yaml security: # ... firewalls: @@ -136,7 +139,7 @@ By default, this bundle will look for `email` field on user class to retrieve it for 1 day, and will set a `password` field when sent. Here is the default configuration: ```yml -# app/config/config.yml +# config/packages/coop_tilleuls_forgot_password.yaml coop_tilleuls_forgot_password: password_token: class: App\Entity\PasswordToken # required diff --git a/Resources/doc/usage.md b/Resources/doc/usage.md index fc46b33..0c86e4e 100644 --- a/Resources/doc/usage.md +++ b/Resources/doc/usage.md @@ -11,7 +11,8 @@ On the first user story, user will send its identifier (email, username...), you allowing him to reset its password using a valid PasswordToken. ```php -namespace AppBundle\EventSubscriber; +// src/EventSubscriber/ForgotPasswordEventSubscriber.php +namespace App\EventSubscriber; // ... use CoopTilleuls\ForgotPasswordBundle\Event\CreateTokenEvent; @@ -49,7 +50,7 @@ final class ForgotPasswordEventSubscriber implements EventSubscriberInterface ->to($user->getEmail()) ->subject('Reset your password') ->html($this->twig->render( - 'AppBundle:ResetPassword:mail.html.twig', + 'App:ResetPassword:mail.html.twig', [ 'reset_password_url' => sprintf('http://www.example.com/forgot-password/%s', $passwordToken->getToken()), ] @@ -74,7 +75,8 @@ Your app is ready to receive a JSON request like: On the second user story, user will send its new password, and you'll have to encode it and save it. ```php -namespace AppBundle\Event; +// src/EventSubscriber/ForgotPasswordEventSubscriber.php +namespace App\EventSubscriber; // ... use CoopTilleuls\ForgotPasswordBundle\Event\UpdatePasswordEvent; diff --git a/Resources/doc/use_custom_manager.md b/Resources/doc/use_custom_manager.md index ba9caf6..d2c7c76 100644 --- a/Resources/doc/use_custom_manager.md +++ b/Resources/doc/use_custom_manager.md @@ -9,7 +9,8 @@ Supposing you want to use your custom entity manager, you'll have to create a se `CoopTilleuls\ForgotPasswordBundle\Manager\Bridge\ManagerInterface`: ```php -namespace AppBundle\Manager; +// src/Manager/FooManager.php +namespace App\Manager; use CoopTilleuls\ForgotPasswordBundle\Manager\Bridge\ManagerInterface; @@ -43,23 +44,13 @@ class FooManager implements ManagerInterface } ``` -Now, declare it as service: - -```yml -# AppBundle/Resources/config/services.yml -services: - app.manager.foo: - class: AppBundle/Manager/FooManager - arguments: ['@foo'] -``` - ## Update configuration Update your configuration to set your service as default one to use by CoopTilleulsForgotPasswordBundle: ```yml -# app/config/config.yml +# config/packages/coop_tilleuls_forgot_password.yaml coop_tilleuls_forgot_password: # ... - manager: 'app.manager.foo' + manager: 'App\Manager\FooManager' ``` diff --git a/Resources/doc/user_not_authenticated.md b/Resources/doc/user_not_authenticated.md index 303f66e..a9afdab 100644 --- a/Resources/doc/user_not_authenticated.md +++ b/Resources/doc/user_not_authenticated.md @@ -7,18 +7,25 @@ application. Create an EventListener and listen to `kernel.request` event: ```php -namespace AppBundle\Event; +// src/EventSubscriber/ForgotPasswordEventSubscriber.php +namespace App\EventSubscriber; // ... +use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Core\User\UserInterface; -class ForgotPasswordEventListener +final class ForgotPasswordEventSubscriber implements EventSubscriberInterface { - // ... - /** - * @param RequestEvent $event - */ + public static function getSubscribedEvents() + { + return [ + // Symfony 4.3 and inferior, use 'kernel.request' event name + KernelEvents::REQUEST => 'onKernelRequest', + ]; + } + public function onKernelRequest(RequestEvent $event) { if (!$event->isMasterRequest() @@ -35,13 +42,3 @@ class ForgotPasswordEventListener } } ``` - -Register this service: - -```yml -# AppBundle/Resources/config/services.yml -services: - app.listener.forgot_password: - tags: - - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest } -```