Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. ewz_recaptcha:
  2. public_key: 6LeKxgcUAAAAANAupGHbpGvRcJnUjepi9Z4NIkeH
  3. private_key: 6LeKxgcUAAAAAIewN_l4ZL2AGhRKRMtmT_VmoMkD
  4. locale_key: %kernel.default_locale%
  5. ajax: true
  6. enabled: true
  7.  
  8. namespace AppBundleForm;
  9.  
  10. use SymfonyComponentFormAbstractType;
  11. use SymfonyComponentFormFormBuilderInterface;
  12. use SymfonyComponentOptionsResolverOptionsResolver;
  13. use SymfonyComponentFormExtensionCoreTypeEmailType;
  14. use SymfonyComponentFormExtensionCoreTypeTextType;
  15. use SymfonyComponentFormExtensionCoreTypeRepeatedType;
  16. use SymfonyComponentFormExtensionCoreTypePasswordType;
  17. use EWZBundleRecaptchaBundleFormTypeEWZRecaptchaType;
  18. use EWZBundleRecaptchaBundleValidatorConstraints as Recaptcha;
  19.  
  20. class UserType extends AbstractType
  21. {
  22. public function buildForm(FormBuilderInterface $builder, array $options)
  23. {
  24. $builder
  25. ->add('email', EmailType::class)
  26. ->add('username', TextType::class)
  27. ->add('plainPassword', RepeatedType::class, array('type' =>
  28. PasswordType::class,'first_options' => array('label'
  29. 'Password'),'second_options' => array('label' => 'Repeat Password'),))
  30.  
  31. ->add('recaptcha', EWZRecaptchaType::class);
  32. }
  33.  
  34. public function configureOptions(OptionsResolver $resolver)
  35. {
  36. $resolver->setDefaults(array(
  37. 'data_class' => 'AppBundleEntityUser',
  38. ));
  39. }
  40. }
  41.  
  42. namespace AppBundleController;
  43.  
  44. use AppBundleFormUserType;
  45. use AppBundleEntityUser;
  46. use SensioBundleFrameworkExtraBundleConfigurationRoute;
  47. use SymfonyBundleFrameworkBundleControllerController;
  48. use SymfonyComponentHttpFoundationRequest;
  49.  
  50. class RegistrationController extends Controller
  51. {
  52. /**
  53. * @Route("/register", name="user_registration")
  54. */
  55. public function registerAction(Request $request)
  56. {
  57. // 1) build the form
  58. $user = new User();
  59. $form = $this->createForm(UserType::class, $user);
  60.  
  61. // 2) handle the submit (will only happen on POST)
  62. $form->handleRequest($request);
  63. if ($form->isSubmitted() && $form->isValid()) {
  64.  
  65. // 3) Encode the password (you could also do this via Doctrine listener)
  66.  
  67. $password = $this->get('security.password_encoder')
  68. ->encodePassword($user, $user->getPlainPassword());
  69. $user->setPassword($password);
  70.  
  71. // 4) save the User!
  72. $em = $this->getDoctrine()->getManager();
  73. $em->persist($user);
  74. $em->flush();
  75.  
  76. // ... do any other work - like sending them an email, etc
  77. // maybe set a "flash" success message for the user
  78.  
  79. return $this->redirectToRoute('replace_with_some_route');
  80. }
  81.  
  82. return $this->render(
  83. 'default/register.html.twig',
  84. array('form' => $form->createView())
  85. );
  86. }
  87. /**
  88.  
  89. @RecaptchaIsTrue */
  90. public $recaptcha;
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement