Created
January 10, 2014 06:56
-
-
Save mstaples/8347963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function registrationSubmit() { | |
$.post( '{{ path( 'onn_user_registration_register', { 'active': 'yes' }) }}', | |
$('#form_registration').serialize(), | |
function(data){ | |
$('#registration').empty().append(data); | |
$('#result_registration').empty().append('Submitted'); | |
var erase_result = function() { $('#result_registration').empty(); } | |
setTimeout(erase_result, 2000); | |
} | |
); | |
return false; | |
} | |
</script> | |
<div id="registration"> | |
{% set form_message = app.session.get('form_message') %} | |
{% if form_message|length > 0 %} | |
<div class="alert alert-error"> | |
{{ form_message }} | |
</div> | |
{% endif %} | |
<form id='form_registration' method="post" {{ form_enctype(form) }} name="registration" > | |
{{ form_widget(form) }} | |
<button onclick='registrationSubmit()' value='Submit' class="btn btn-large btn-success" style="margin:10px;">Create New Account</button> | |
</form> | |
<div id='result_registration'></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ONN\UserBundle\Controller; | |
use FOS\UserBundle\FOSUserEvents; | |
use FOS\UserBundle\Event\FormEvent; | |
use FOS\UserBundle\Event\GetResponseUserEvent; | |
use FOS\UserBundle\Event\FilterUserResponseEvent; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\RedirectResponse; | |
use FOS\UserBundle\Controller\RegistrationController as BaseController; | |
class RegistrationController extends BaseController | |
{ | |
public function registerAction(Request $request,$active = null) | |
{ | |
if ($active != null){ | |
throw new \Exception('registerAction reached'); | |
} | |
/** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */ | |
$formFactory = $this->container->get('fos_user.registration.form.factory'); | |
/** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ | |
$userManager = $this->container->get('fos_user.user_manager'); | |
/** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ | |
$dispatcher = $this->container->get('event_dispatcher'); | |
$user = $userManager->createUser(); | |
$user->setEnabled(true); | |
$event = new GetResponseUserEvent($user, $request); | |
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event); | |
if (null !== $event->getResponse()) { | |
//var_dump($event->getResponse()); | |
//throw new \Exception("event"); | |
return $event->getResponse(); | |
} | |
$form = $formFactory->createForm(); | |
$form->setData($user); | |
if ($active == 'yes') { | |
throw new \Exception('yes'); | |
$form->bind($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->container->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->container->get('templating')->renderResponse('ONNUserBundle:Registration:register.html.twig', array( | |
'form' => $form->createView(), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment