The SherlockodeUserConfirmationBundle provides a way to create a user account that will stay disabled until the user visits a confirmation link sent by email and sets a password.
This version of the bundle requires Symfony 3.* or 4.* and FOSUserBundle
Install with Composer:
$ composer require sherlockode/user-confirmation-bundle
Enable the bundle in the Symfony kernel:
<?php
// config/bundles.php
return [
// ...
Sherlockode\UserConfirmationBundle\SherlockodeUserConfirmationBundle::class => ['all' => true],
];
Import the routing in config/routes.yaml
sherlockode_user_confirmation:
resource: "@SherlockodeUserConfirmationBundle/Resources/config/routing.xml"
Then create the configuration in config/packages/sherlockode_user_confirmation.yaml
sherlockode_user_confirmation:
from_email: [email protected] # From email address
from_name: John Doe # Name of the expeditor
email_subject: Please confirm your account # The subject for the confirmation email (optional)
redirect_after_confirmation: admin_dashboard # The route name to redirect the user after confirmation
To extend the confirmation form template, just update your sherlockode_user_confirmation.yaml
sherlockode_user_confirmation:
templates:
confirmation_form: 'Registration/confirmation.html.twig'
Then in your template, add a placeholder for the block sherlockode_user_confirmation_form
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<h1>My awesome app !</h1>
<div>
{# The form will be render here #}
{% block sherlockode_user_confirmation_form %}{% endblock %}
</div>
</body>
</html>
If you want to extend the confirmation email template, you should add the path in your config.yml
sherlockode_user_confirmation:
templates:
confirmation_email: 'Email/registration.html.twig'
In this template, you have access to the user
object, and to a variable named confirmationUrl
which contains the url to access the confirmation form.
If you want to send the confirmation again for an existing user, use the following link :
<a href="{{ path('sherlockode_user_confirmation_send_confirmation', {id: userId}) }}">
Send confirmation email
</a>