• <legend id='RLns6'><style id='RLns6'><dir id='RLns6'><q id='RLns6'></q></dir></style></legend>
      <i id='RLns6'><tr id='RLns6'><dt id='RLns6'><q id='RLns6'><span id='RLns6'><b id='RLns6'><form id='RLns6'><ins id='RLns6'></ins><ul id='RLns6'></ul><sub id='RLns6'></sub></form><legend id='RLns6'></legend><bdo id='RLns6'><pre id='RLns6'><center id='RLns6'></center></pre></bdo></b><th id='RLns6'></th></span></q></dt></tr></i><div id='RLns6'><tfoot id='RLns6'></tfoot><dl id='RLns6'><fieldset id='RLns6'></fieldset></dl></div>
    1. <small id='RLns6'></small><noframes id='RLns6'>

      <tfoot id='RLns6'></tfoot>
      • <bdo id='RLns6'></bdo><ul id='RLns6'></ul>

        Symfony2 FOSUserBundle 扩展注册表导致重复的电子邮件验证

        时间:2023-08-18
        <legend id='lNDMB'><style id='lNDMB'><dir id='lNDMB'><q id='lNDMB'></q></dir></style></legend>

          <bdo id='lNDMB'></bdo><ul id='lNDMB'></ul>
        • <i id='lNDMB'><tr id='lNDMB'><dt id='lNDMB'><q id='lNDMB'><span id='lNDMB'><b id='lNDMB'><form id='lNDMB'><ins id='lNDMB'></ins><ul id='lNDMB'></ul><sub id='lNDMB'></sub></form><legend id='lNDMB'></legend><bdo id='lNDMB'><pre id='lNDMB'><center id='lNDMB'></center></pre></bdo></b><th id='lNDMB'></th></span></q></dt></tr></i><div id='lNDMB'><tfoot id='lNDMB'></tfoot><dl id='lNDMB'><fieldset id='lNDMB'></fieldset></dl></div>

          <small id='lNDMB'></small><noframes id='lNDMB'>

                    <tbody id='lNDMB'></tbody>
                  <tfoot id='lNDMB'></tfoot>
                  本文介绍了Symfony2 FOSUserBundle 扩展注册表导致重复的电子邮件验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个自定义的注册表单类型定义如下:

                  I have a custom registration form type defined like this:

                  ....
                  public function buildForm(FormBuilderInterface $builder, array $options)
                      {
                          parent::buildForm($builder, $options);
                  
                          $builder
                              ->remove('username')
                              ->add('firstName')
                              ->add('lastName')
                              ->add('hei', 'entity', array(
                                  'class' => 'AcmeAcmeBundle:HigherEducationalInstitution',
                                  'label' => 'Higher Educational Institution'
                              ));
                  
                      }
                  ....
                  

                  自定义控制器的工作方式与 FOSUserbundle 中的控制器几乎相同,并且还会检查有效表单

                  The custom controller works pretty much the same as the one in the FOSUserbundle and also checks for a valid form

                  ...
                  public function registerAsStudentAction(Request $request)
                      {
                          /** @var $formFactory FOSUserBundleFormFactoryFactoryInterface */
                          $formFactory = $this->get('acme.user_form_factory');
                          /** @var $userManager FOSUserBundleModelUserManagerInterface */
                          $userManager = $this->get('fos_user.user_manager');
                          /** @var $dispatcher SymfonyComponentEventDispatcherEventDispatcherInterface */
                          $dispatcher = $this->get('event_dispatcher');
                  
                          $user = $userManager->createUser();
                          $user->setEnabled(true);
                  
                          $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, new UserEvent($user, $request));
                  
                          $form = $formFactory->getStudentRegistrationForm();
                          $form->setData($user);
                  
                          if ('POST' === $request->getMethod()) {
                              $form->bind($request);
                  
                              if ($form->isValid()) {
                                  $event = new FormEvent($form, $request);
                                  $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
                  
                                  $user->addRole('ROLE_STUDENT');
                  
                                  $userManager->updateUser($user);
                  
                  
                                  if (null === $response = $event->getResponse()) {
                                      $url = $this->get('router')->generate('fos_user_registration_confirmed');
                                      $response = new RedirectResponse($url);
                                  }
                  
                                  $dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
                  
                                  return $response;
                              }
                          }
                  
                          return $this->render('AcmeUserBundle:Registration:register_student.html.twig', array('form' => $form->createView()));
                      }
                  ....
                  

                  当我尝试使用已在使用的电子邮件地址进行注册时,我收到了一个原则性例外,即电子邮件上唯一键的重复条目.

                  When I try to register with an email address that's already in use I'm getting a doctrine exception for a duplicate entry for a unique key on the email.

                  在正常的注册表单中,我收到一个表单错误,显示电子邮件地址已被使用.表单如何通过在我的表单中但在原始注册表中没有重复电子邮件地址的验证器?

                  In the normal registration form I'm getting a form error displaying that the email address was already used. How can the form pass the validator with a duplicate email address in my form but not in the original registration form?

                  推荐答案

                  通过在 AcmeBundle/Resources/config 中添加额外的validation.yml 来修复它

                  Fixed it by adding extra validation.yml to AcmeBundle/Resources/config

                  AcmeUserBundleEntityUser:
                      constraints:
                          - SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity: { fields: email, message: "This email has already been registered"}
                          - SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity: emailCanonical
                      properties:
                          email:
                              - Email: ~
                          emailCanonical:
                              - Email:  ~
                          plainPassword:
                              - Length:
                                  min: 7
                                  minMessage: "Your password must be at least {{ limit }} characters"
                  

                  这篇关于Symfony2 FOSUserBundle 扩展注册表导致重复的电子邮件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Symfony2 同一类中的多个实体 下一篇:Doctrine:将 CURRENT_TIMESTAMP 设置为数据库的默认值(即不是 PHP)

                  相关文章

                  <tfoot id='Kujkv'></tfoot>
                1. <legend id='Kujkv'><style id='Kujkv'><dir id='Kujkv'><q id='Kujkv'></q></dir></style></legend>

                    • <bdo id='Kujkv'></bdo><ul id='Kujkv'></ul>
                    1. <small id='Kujkv'></small><noframes id='Kujkv'>

                      <i id='Kujkv'><tr id='Kujkv'><dt id='Kujkv'><q id='Kujkv'><span id='Kujkv'><b id='Kujkv'><form id='Kujkv'><ins id='Kujkv'></ins><ul id='Kujkv'></ul><sub id='Kujkv'></sub></form><legend id='Kujkv'></legend><bdo id='Kujkv'><pre id='Kujkv'><center id='Kujkv'></center></pre></bdo></b><th id='Kujkv'></th></span></q></dt></tr></i><div id='Kujkv'><tfoot id='Kujkv'></tfoot><dl id='Kujkv'><fieldset id='Kujkv'></fieldset></dl></div>