public function processAction(Request $req, Application $app) { $form_data = array('formAction' => '/signup', 'first_name' => $req->get('first_name'), 'last_name' => $req->get('last_name'), 'company' => $req->get('company'), 'twitter' => $req->get('twitter'), 'email' => $req->get('email'), 'password' => $req->get('password'), 'password2' => $req->get('password2'), 'airport' => $req->get('airport'), 'buttonInfo' => 'Create my speaker profile'); $form_data['speaker_info'] = $req->get('speaker_info') ?: null; $form_data['speaker_bio'] = $req->get('speaker_bio') ?: null; $form_data['transportation'] = $req->get('transportation') ?: null; $form_data['hotel'] = $req->get('hotel') ?: null; $form_data['speaker_photo'] = null; if ($req->files->get('speaker_photo') !== null) { $form_data['speaker_photo'] = $req->files->get('speaker_photo'); } $form = new SignupForm($form_data, $app['purifier']); $form->sanitize(); $isValid = $form->validateAll(); if ($isValid) { $sanitized_data = $form->getCleanData(); // process the speaker photo $this->processSpeakerPhoto($form_data, $app); // Remove leading @ for twitter $sanitized_data['twitter'] = preg_replace('/^@/', '', $sanitized_data['twitter']); // Create account using Sentry try { $user_data = array('first_name' => $sanitized_data['first_name'], 'last_name' => $sanitized_data['last_name'], 'company' => $sanitized_data['company'], 'twitter' => $sanitized_data['twitter'], 'email' => $sanitized_data['email'], 'password' => $sanitized_data['password'], 'airport' => $sanitized_data['airport'], 'activated' => 1); $user = $app['sentry']->getUserProvider()->create($user_data); // Add them to the proper group $user->addGroup($app['sentry']->getGroupProvider()->findByName('Speakers')); // Add in the extra speaker information $mapper = $app['spot']->mapper('\\OpenCFP\\Entity\\User'); $speaker = $mapper->get($user->id); $speaker->info = $sanitized_data['speaker_info']; $speaker->bio = $sanitized_data['speaker_bio']; $speaker->photo_path = $sanitized_data['speaker_photo']; $mapper->save($speaker); // Set Success Flash Message $app['session']->set('flash', array('type' => 'success', 'short' => 'Success', 'ext' => "You've successfully created your account!")); return $app->redirect($app['url'] . '/login'); } catch (UserExistsException $e) { $app['session']->set('flash', array('type' => 'error', 'short' => 'Error', 'ext' => 'A user already exists with that email address')); } } if (!$isValid) { // Set Error Flash Message $app['session']->set('flash', array('type' => 'error', 'short' => 'Error', 'ext' => implode("<br>", $form->getErrorMessages()))); } $template = $app['twig']->loadTemplate('user/create.twig'); $form_data['flash'] = $this->getFlash($app); return $template->render($form_data); }
public function passwordProcessAction(Request $req, Application $app) { if (!$app['sentry']->check()) { return $app->redirect($app['url'] . '/login'); } $user = $app['sentry']->getUser(); /** * Okay, the logic is kind of weird but we can use the SignupFOrm * validation code to make sure our password changes are good */ $formData = array('password' => $req->get('password'), 'password2' => $req->get('password_confirm')); $form = new SignupForm($formData, $app['purifier']); $form->sanitize(); if ($form->validatePasswords() === false) { $app['session']->set('flash', array('type' => 'error', 'short' => 'Error', 'ext' => implode("<br>", $form->getErrorMessages()))); return $app->redirect($app['url'] . '/profile/change_password'); } /** * Resetting passwords looks weird because we need to use Sentry's * own built-in password reset functionality to do it */ $sanitized_data = $form->getCleanData(); $reset_code = $user->getResetPasswordCode(); if (!$user->attemptResetPassword($reset_code, $sanitized_data['password'])) { $app['session']->set('flash', array('type' => 'error', 'short' => 'Error', 'ext' => "Unable to update your password in the database. Please try again.")); return $app->redirect($app['url'] . '/profile/change_password'); } $app['session']->set('flash', array('type' => 'success', 'short' => 'Success', 'ext' => "Changed your password.")); return $app->redirect($app['url'] . '/profile/change_password'); }