Ejemplo n.º 1
0
 /**
  * Handles the registration. Validates and creates the member, then redirects
  * to the appropriate place
  *  
  * @param  array $data
  * @param  BootstrapForm $form
  * @return SSViewer
  */
 public function doRegister($data, $form)
 {
     try {
         Session::set("FormInfo.{$form->getName()}.data", $data);
         $member = Member::get()->filter('Email', $data['Email'])->first();
         if ($member) {
             $form->sessionMessage('Bah! We\'ve already got a user with that email.', 'bad');
             return $this->redirectBack();
         }
         if ($data['Password'] != $data['Password_confirm']) {
             $form->sessionMessage('Passwords do not match.', 'bad');
             return $this->redirectBack();
         }
         $member = Member::create(array('FirstName' => $data['FirstName'], 'Surname' => $data['Surname'], 'Email' => $data['Email'], 'Password' => $data['Password']));
         $member->write();
         if (!empty($data[SpeakerRegistrationRequest::ConfirmationTokenParamName])) {
             $speaker_registration_token = $data[SpeakerRegistrationRequest::ConfirmationTokenParamName];
             $this->speaker_registration_request_manager->confirm($speaker_registration_token, $member);
         }
         $member->addToGroupByCode('speakers');
         $member->sendWelcomeEmail();
         Session::clear("FormInfo.{$form->getName()}.data");
         if ($data['BackURL']) {
             $redirect = HTTP::setGetVar('welcome', 1, $data['BackURL']);
             return OpenStackIdCommon::loginMember($member, $redirect);
         }
         $form->sessionMessage('Awesome! You should receive an email shortly.', 'good');
         return OpenStackIdCommon::loginMember($member, $this->redirectBackUrl());
     } catch (Exception $ex) {
         SS_Log::log($ex, SS_Log::WARN);
         return $this->httpError(404, $ex->getMessage());
     }
 }
 /**
  * @param IPresentation $presentation
  * @param string $email
  * @param Member|null $member
  * @param IPresentationSpeaker|null $speaker
  * @return IPresentationSpeaker
  */
 public function addSpeakerByEmailTo(IPresentation $presentation, $email, Member $member = null, IPresentationSpeaker $speaker = null)
 {
     return $this->tx_manager->transaction(function () use($presentation, $email, $member, $speaker) {
         $speaker = !is_null($speaker) ? $speaker : $this->speaker_repository->getByEmail($email);
         if (is_null($speaker) && !is_null($member)) {
             $speaker = $member->getSpeakerProfile();
         }
         if (!is_null($speaker) && !is_null($member) && intval($member->ID) !== intval($speaker->MemberID)) {
             throw new EntityValidationException(sprintf('speaker does not belongs to selected member!'));
         }
         if (!$speaker) {
             // create it
             $speaker = PresentationSpeaker::create();
             $speaker->write();
             if (!is_null($member)) {
                 $speaker->MemberID = $member->ID;
                 $member->addToGroupByCode('speakers');
                 $member->write();
             } else {
                 $speaker->MemberID = 0;
                 $request = $this->speaker_registration_manager->register($speaker, $email);
                 $speaker->RegistrationRequestID = $request->getIdentifier();
             }
             $speaker->write();
         }
         // i am adding other speaker than me
         if (!is_null($member) && intval($member->ID) !== intval(Member::currentUserID()) && !$this->canAddSpeakerOnPresentation($speaker, $presentation)) {
             throw new EntityValidationException(sprintf("You reached the max. allowed # of presentations for speaker %s (%s)", $speaker->getName(), $email));
         }
         if ($speaker->Presentations()->filter('PresentationID', $presentation->ID)->count() > 0 || $presentation->ModeratorID == $speaker->ID) {
             throw new EntityValidationException('Speaker already assigned to this presentation!.');
         }
         // The first one is the moderator.
         if (!$presentation->maxModeratorsReached()) {
             $presentation->ModeratorID = $speaker->ID;
         } else {
             $speaker->Presentations()->add($presentation);
             $speaker->write();
         }
         return $speaker;
     });
 }