Advertisement
Guest User

Untitled

a guest
Sep 1st, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.95 KB | None | 0 0
  1. An exception occurred while executing 'INSERT INTO fos_user (username, username_canonical, email, email_canonical, enabled, salt, password, last_login, locked, expired, expires_at, confirmation_token, password_requested_at, roles, credentials_expired, credentials_expire_at, sex) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params [null, null, null, null, 1, "np04lzt9veo4ow8kc88w8ocgsc4sg4g", null, null, 0, 0, null, null, null, "a:0:{}", 0, null, "Homme"]:
  2.  
  3. SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'username' cannot be null
  4.  
  5. namespace BISSAPUserBundleController;
  6.  
  7. use FOSUserBundleFOSUserEvents;
  8. use FOSUserBundleEventFormEvent as FormEvent;
  9. use FOSUserBundleEventGetResponseUserEvent;
  10. use FOSUserBundleEventFilterUserResponseEvent;
  11. use SymfonyBundleFrameworkBundleControllerController;
  12. use SymfonyComponentHttpFoundationRequest;
  13. use SymfonyComponentHttpFoundationRedirectResponse;
  14. use SymfonyComponentHttpKernelExceptionNotFoundHttpException;
  15. use SymfonyComponentSecurityCoreExceptionAccessDeniedException;
  16. use FOSUserBundleModelUserInterface;
  17. use BISSAPUserBundleEntityUser;
  18. use BISSAPUserBundleFormRegistrationType as Register;
  19.  
  20.  
  21. /**
  22. * Controller managing the registration
  23. *
  24. * @author Thibault Duplessis <thibault.duplessis@gmail.com>
  25. * @author Christophe Coevoet <stof@notk.org>
  26. */
  27. class RegistrationController extends Controller
  28. {
  29. public function registerAction(Request $request)
  30. {
  31. /** @var $formFactory FOSUserBundleFormFactoryFactoryInterface */
  32. $formFactory = $this->get('fos_user.registration.form.factory');
  33. /** @var $userManager FOSUserBundleModelUserManagerInterface */
  34. $userManager = $this->get('fos_user.user_manager');
  35. /** @var $dispatcher SymfonyComponentEventDispatcherEventDispatcherInterface */
  36. $dispatcher = $this->get('event_dispatcher');
  37. $user = $userManager->createUser();
  38. $user->setEnabled(true);
  39. $event = new GetResponseUserEvent($user, $request);
  40. $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
  41. if (null !== $event->getResponse()) {
  42. return $event->getResponse();
  43. }
  44.  
  45. $form = $this->createForm(Register::Class, $user, array('allow_extra_fields' =>true));
  46.  
  47. //$form = $formFactory->createForm();
  48. $form->setData($user);
  49. $form->handleRequest($request);
  50. $ERR = $form->getErrors();
  51.  
  52.  
  53. if ($form->isValid()) {
  54. // dump($user);
  55. // die();
  56. $event = new FormEvent($form, $request);
  57. $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
  58. $userManager->updateUser($user);
  59. if (null === $response = $event->getResponse()) {
  60. $url = $this->generateUrl('fos_user_registration_confirmed');
  61. $response = new RedirectResponse($url);
  62. }
  63.  
  64. $dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
  65. return $response;
  66. }
  67. return $this->render('BISSAPUserBundle:Registration:register.html.twig', array(
  68. //return $this->render('BISSAPBenevolesBundle:Default:index.html.twig', array(
  69. 'form' => $form->createView(),'ERR' => $ERR
  70. ));
  71. }
  72. /**
  73. * Tell the user to check his email provider
  74. */
  75. public function checkEmailAction()
  76. {
  77. $email = $this->get('session')->get('fos_user_send_confirmation_email/email');
  78. $this->get('session')->remove('fos_user_send_confirmation_email/email');
  79. $user = $this->get('fos_user.user_manager')->findUserByEmail($email);
  80. if (null === $user) {
  81. throw new NotFoundHttpException(sprintf('The user with email "%s" does not exist', $email));
  82. }
  83. return $this->render('FOSUserBundle:Registration:checkEmail.html.twig', array(
  84. 'user' => $user,
  85. ));
  86. }
  87. /**
  88. * Receive the confirmation token from user email provider, login the user
  89. */
  90. public function confirmAction(Request $request, $token)
  91. {
  92. /** @var $userManager FOSUserBundleModelUserManagerInterface */
  93. $userManager = $this->get('fos_user.user_manager');
  94. $user = $userManager->findUserByConfirmationToken($token);
  95. if (null === $user) {
  96. throw new NotFoundHttpException(sprintf('The user with confirmation token "%s" does not exist', $token));
  97. }
  98. /** @var $dispatcher SymfonyComponentEventDispatcherEventDispatcherInterface */
  99. $dispatcher = $this->get('event_dispatcher');
  100. $user->setConfirmationToken(null);
  101. $user->setEnabled(true);
  102. $event = new GetResponseUserEvent($user, $request);
  103. $dispatcher->dispatch(FOSUserEvents::REGISTRATION_CONFIRM, $event);
  104. $userManager->updateUser($user);
  105. if (null === $response = $event->getResponse()) {
  106. $url = $this->generateUrl('fos_user_registration_confirmed');
  107. $response = new RedirectResponse($url);
  108. }
  109. $dispatcher->dispatch(FOSUserEvents::REGISTRATION_CONFIRMED, new FilterUserResponseEvent($user, $request, $response));
  110. return $response;
  111. }
  112. /**
  113. * Tell the user his account is now confirmed
  114. */
  115. public function confirmedAction()
  116. {
  117. $user = $this->getUser();
  118. if (!is_object($user) || !$user instanceof UserInterface) {
  119. throw new AccessDeniedException('This user does not have access to this section.');
  120. }
  121. return $this->render('FOSUserBundle:Registration:confirmed.html.twig', array(
  122. 'user' => $user,
  123. 'targetUrl' => $this->getTargetUrlFromSession(),
  124. ));
  125. }
  126. private function getTargetUrlFromSession()
  127. {
  128. // Set the SecurityContext for Symfony <2.6
  129. if (interface_exists('SymfonyComponentSecurityCoreAuthenticationTokenStorageTokenStorageInterface')) {
  130. $tokenStorage = $this->get('security.token_storage');
  131. } else {
  132. $tokenStorage = $this->get('security.context');
  133. }
  134. $key = sprintf('_security.%s.target_path', $tokenStorage->getToken()->getProviderKey());
  135. if ($this->get('session')->has($key)) {
  136. return $this->get('session')->get($key);
  137. }
  138. }
  139. }
  140.  
  141. namespace BISSAPUserBundleForm;
  142.  
  143. use SymfonyComponentFormAbstractType;
  144. use SymfonyComponentFormFormBuilderInterface;
  145. use SymfonyComponentFormExtensionCoreTypeChoiceType;
  146. use SymfonyComponentFormExtensionCoreTypeButtonType;
  147.  
  148. class RegistrationType extends AbstractType
  149. {
  150.  
  151.  
  152. public function buildForm(FormBuilderInterface $builder, array $options)
  153. {
  154.  
  155.  
  156. $builder->add('sex', ChoiceType::class, array(
  157. 'choices' => array(
  158. 'Homme' => 'Homme',
  159. 'Femme' => 'Femme',
  160. 'Unknow' => 'Unknow',
  161. ),
  162. ));
  163. $builder->add('Enregistrer', ButtonType::class, array(
  164. 'attr' => array(
  165. 'class' => 'registerbox__submit bc-btn',)));
  166. }
  167. /*
  168. public function getDefaultOptions()
  169. {
  170. return array(
  171. 'validation_groups' => array('registration', 'Default')
  172. );
  173. }
  174. */
  175. public function setDefaultOptions(OptionsResolverInterface $resolver)
  176. {
  177. $resolver->setDefaults(
  178. array(
  179. 'allow_extra_fields' => true
  180. )
  181. );
  182. }
  183.  
  184. public function getParent()
  185. {
  186. return 'FOSUserBundleFormTypeRegistrationFormType';
  187. }
  188.  
  189. public function getBlockPrefix()
  190. {
  191. return 'app_user_registration';
  192. }
  193.  
  194. }
  195.  
  196. RegistrationController.php on line 61:
  197. User {#381 ▼
  198. #id: null
  199. +sex: "Homme"
  200. #username: null
  201. #usernameCanonical: null
  202. #email: null
  203. #emailCanonical: null
  204. #enabled: true
  205. #salt: "h5asnpkagfcos0w0kc84ksosc40cgwg"
  206. #password: null
  207. #plainPassword: null
  208. #lastLogin: null
  209. #confirmationToken: null
  210. #passwordRequestedAt: null
  211. #groups: null
  212. #locked: false
  213. #expired: false
  214. #expiresAt: null
  215. #roles: []
  216. #credentialsExpired: false
  217. #credentialsExpireAt: null
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement