sherlockode / user-confirmation-bundle
Symfony 扩展包,用于用户注册确认过程
v0.4.3
2022-08-31 15:50 UTC
Requires
- php: ^7.4|^8.0
- friendsofsymfony/user-bundle: ^2.2.4|^3.0
- symfony/framework-bundle: ^4.4|^5.0
- symfony/mailer: ^5.0
- symfony/twig-bundle: ^4.4|^5.0
- twig/twig: ^2.0|^3.0
README
SherlockodeUserConfirmationBundle 提供了一种创建用户账户的方式,该账户在用户通过电子邮件收到的确认链接访问并设置密码之前将保持禁用状态。
先决条件
此版本的扩展包需要 Symfony 3.* 或 4.* 以及 FOSUserBundle
安装
步骤 1:安装 SherlockodeUserConfirmationBundle
使用 Composer 安装
$ composer require sherlockode/user-confirmation-bundle
在 Symfony 内核中启用扩展包
<?php // config/bundles.php return [ // ... Sherlockode\UserConfirmationBundle\SherlockodeUserConfirmationBundle::class => ['all' => true], ];
步骤 2:配置扩展包
在 config/routes.yaml
中导入路由
sherlockode_user_confirmation: resource: "@SherlockodeUserConfirmationBundle/Resources/config/routing.xml"
然后在 config/packages/sherlockode_user_confirmation.yaml
中创建配置
sherlockode_user_confirmation: from_email: no-reply@awesome.com # 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
自定义
扩展确认表单模板
要扩展确认表单模板,只需更新你的 sherlockode_user_confirmation.yaml
sherlockode_user_confirmation: templates: confirmation_form: 'Registration/confirmation.html.twig'
然后在你的模板中,为 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>
扩展确认电子邮件
如果你想扩展确认电子邮件模板,你应该在 config.yml
中添加路径
sherlockode_user_confirmation: templates: confirmation_email: 'Email/registration.html.twig'
在这个模板中,你可以访问 user
对象,以及一个名为 confirmationUrl
的变量,它包含访问确认表单的 URL。
发送确认电子邮件
如果你想为现有用户再次发送确认电子邮件,请使用以下链接
<a href="{{ path('sherlockode_user_confirmation_send_confirmation', {id: userId}) }}"> Send confirmation email </a>