Example #1
0
 /**
  * @test
  */
 public function formRejectsValidationOnInvalidSpeakerPhoto()
 {
     // Mock speaker photo.
     $photo = m::mock('stdClass');
     $photo->shouldReceive('isValid')->andReturn(false);
     $photo->shouldReceive('getErrorMessage')->andReturn('stubbed error message');
     $form = new SignupForm(['speaker_photo' => $photo], $this->purifier);
     $form->validateSpeakerPhoto();
     $this->assertTrue($form->hasErrors());
     $this->assertContains('stubbed error message', $form->getErrorMessages()[0]);
 }
Example #2
0
 public function processAction(Request $req, Application $app)
 {
     $form_data = array('formAction' => $this->url('user_create'), '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']);
     $isValid = $form->validateAll();
     if ($isValid) {
         $sanitized_data = $form->getCleanData();
         if (isset($form_data['speaker_photo'])) {
             /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
             $file = $form_data['speaker_photo'];
             /** @var \OpenCFP\ProfileImageProcessor $processor */
             $processor = $app['profile_image_processor'];
             $sanitized_data['speaker_photo'] = $form_data['first_name'] . '.' . $form_data['last_name'] . uniqid() . '.' . $file->getClientOriginalExtension();
             $processor->process($file, $sanitized_data['speaker_photo']);
         }
         // 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\\Domain\\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'];
             $speaker->transportation = (int) $sanitized_data['transportation'];
             $speaker->hotel = (int) $sanitized_data['hotel'];
             $mapper->save($speaker);
             // Set Success Flash Message
             $app['session']->set('flash', array('type' => 'success', 'short' => 'Success', 'ext' => "You've successfully created your account!"));
             return $this->redirectTo('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())));
     }
     $form_data['flash'] = $this->getFlash($app);
     return $this->render('user/create.twig', $form_data);
 }
Example #3
0
 public function passwordProcessAction(Request $req)
 {
     if (!$this->app['sentry']->check()) {
         return $this->redirectTo('login');
     }
     $user = $this->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, $this->app['purifier']);
     $form->sanitize();
     if ($form->validatePasswords() === false) {
         $this->app['session']->set('flash', array('type' => 'error', 'short' => 'Error', 'ext' => implode("<br>", $form->getErrorMessages())));
         return $this->redirectTo('password_edit');
     }
     /**
      * 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'])) {
         $this->app['session']->set('flash', array('type' => 'error', 'short' => 'Error', 'ext' => "Unable to update your password in the database. Please try again."));
         return $this->redirectTo('password_edit');
     }
     $this->app['session']->set('flash', array('type' => 'success', 'short' => 'Success', 'ext' => "Changed your password."));
     return $this->redirectTo('password_edit');
 }
Example #4
0
 public function processAction(Request $req, Application $app)
 {
     $form_data = ['formAction' => $this->url('user_create'), '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'), 'agree_coc' => $req->get('agree_coc'), 'buttonInfo' => 'Create my speaker profile', 'coc_link' => $this->app->config('application.coc_link')];
     $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'], ['has_coc' => !empty($app->config('application.coc_link'))]);
     $isValid = $form->validateAll();
     if ($isValid) {
         $sanitized_data = $form->getCleanData();
         if (isset($form_data['speaker_photo'])) {
             /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
             $file = $form_data['speaker_photo'];
             /** @var ProfileImageProcessor $processor */
             $processor = $app['profile_image_processor'];
             /** @var PseudoRandomStringGenerator $generator */
             $generator = $app['security.random'];
             /**
              * The extension technically is not required. We guess the extension using a trusted method.
              */
             $sanitized_data['speaker_photo'] = $generator->generate(40) . '.' . $file->guessExtension();
             $processor->process($file, $sanitized_data['speaker_photo']);
         }
         // Create account using Sentry
         try {
             $user_data = ['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];
             /* @var Sentry $sentry */
             $sentry = $app['sentry'];
             $user = $sentry->getUserProvider()->create($user_data);
             // Add them to the proper group
             $user->addGroup($sentry->getGroupProvider()->findByName('Speakers'));
             /* @var Locator $spot */
             $spot = $app['spot'];
             // Add in the extra speaker information
             $mapper = $spot->mapper('\\OpenCFP\\Domain\\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'];
             $speaker->transportation = (int) $sanitized_data['transportation'];
             $speaker->hotel = (int) $sanitized_data['hotel'];
             $mapper->save($speaker);
             // This is for redirecting to OAuth endpoint if we arrived
             // as part of the Authorization Code Grant flow.
             if ($this->service('session')->has('redirectTo')) {
                 $sentry->login($user);
                 return new RedirectResponse($this->service('session')->get('redirectTo'));
             }
             // Set Success Flash Message
             $app['session']->set('flash', ['type' => 'success', 'short' => 'Success', 'ext' => "You've successfully created your account!"]);
             return $this->redirectTo('login');
         } catch (UserExistsException $e) {
             $app['session']->set('flash', ['type' => 'error', 'short' => 'Error', 'ext' => 'A user already exists with that email address']);
         }
     }
     if (!$isValid) {
         // Set Error Flash Message
         $app['session']->set('flash', ['type' => 'error', 'short' => 'Error', 'ext' => implode("<br>", $form->getErrorMessages())]);
     }
     $form_data['flash'] = $this->getFlash($app);
     return $this->render('user/create.twig', $form_data);
 }
Example #5
0
 /**
  * Test that we get back some sanitized data
  *
  * @test
  * @param array $inputData
  * @param array $expectedData
  * @dataProvider sanitizationProvider
  */
 public function dataGetsSanitizedCorrectly($inputData, $expectedData)
 {
     $form = new \OpenCFP\Http\Form\SignupForm($inputData, $this->purifier);
     $form->sanitize();
     $sanitizedData = $form->getCleanData();
     $this->assertEquals($expectedData, $sanitizedData, "Data was not sanitized properly");
 }