[英]Symfony2 - Trying to understand FOSUserBundle Registration confirmation
I am new to Symfony and I pretty much now understand the basics and now I am diving into Events and Events Listeners. 我是Symfony的新手,现在我几乎了解了基础知识,现在我正深入研究Event和Events Listeners。
I understand that when a user registers via FOSUserBundle there are three Events that get dispatched inside registerAction()
我了解到,当用户通过FOSUserBundle注册时,在registerAction()
内部调度了三个事件
This is the registerAction
code 这是registerAction
代码
public function registerAction(Request $request)
{
/** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
$formFactory = $this->get('fos_user.registration.form.factory');
/** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
$userManager = $this->get('fos_user.user_manager');
/** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
$dispatcher = $this->get('event_dispatcher');
$user = $userManager->createUser();
$user->setEnabled(true);
$event = new GetResponseUserEvent($user, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
if (null !== $event->getResponse()) {
return $event->getResponse();
}
$form = $formFactory->createForm();
$form->setData($user);
$form->handleRequest($request);
if ($form->isValid()) {
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
$userManager->updateUser($user);
if (null === $response = $event->getResponse()) {
$url = $this->generateUrl('fos_user_registration_confirmed');
$response = new RedirectResponse($url);
}
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
return $response;
}
return $this->render('FOSUserBundle:Registration:register.html.twig', array(
'form' => $form->createView(),
));
}
Now inside the config.yml
we can setup the configuration so the user is required to confirm their email address before their account gets activated and this is where I get lost 现在在config.yml
我们可以设置配置,以便要求用户在激活帐户之前确认其电子邮件地址,这是我迷路的地方
fos_user:
registration:
confirmation:
enabled: true
I am looking at EmailConfirmationListener which listens to the REGISTRATION_SUCCESS
and inside this code I am finding nothing that tells me how it is reading the confirmation
in config.yml
我正在查看侦听REGISTRATION_SUCCESS
EmailConfirmationListener ,并且在此代码内,我什么都没发现,它告诉我它如何读取config.yml
的confirmation
config.yml
I will really appreciate if someone can explain to me how this listener is triggered based on confirmation
enabled
status. 如果有人可以向我解释如何基于enabled
confirmation
状态触发此侦听器,我将不胜感激。
The symfony doc explains symfony文档解释
In order to load service configuration, you have to create a Dependency Injection (DI) Extension for your bundle 为了加载服务配置,您必须为捆绑包创建一个依赖注入(DI)扩展
I did a search in the repository and, as you can see , the FOSUserExtension.php
file loads a service file which contains the listener declaration. 我在存储库中进行了搜索,如您所见 , FOSUserExtension.php
文件加载了包含侦听器声明的服务文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.