Skip to content

Commit

Permalink
Update documentation (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon authored Aug 21, 2021
1 parent 037580e commit 35dd7ac
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 51 deletions.
41 changes: 22 additions & 19 deletions Resources/doc/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Resources/doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()),
]
Expand All @@ -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;
Expand Down
17 changes: 4 additions & 13 deletions Resources/doc/use_custom_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'
```
29 changes: 13 additions & 16 deletions Resources/doc/user_not_authenticated.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 }
```

0 comments on commit 35dd7ac

Please sign in to comment.