/**
  * @param $email
  * @param IMessageSenderService $sender_service
  * @throws NotFoundEntityException
  * @throws EntityValidationException
  * @return Member
  */
 public function resendEmailVerification($email, IMessageSenderService $sender_service)
 {
     $repository = $this->repository;
     return $this->tx_manager->transaction(function () use($email, $repository, $sender_service) {
         if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
             throw new EntityValidationException('invalid mail address');
         }
         $member = $repository->findByEmail($email);
         if (is_null($member)) {
             throw new NotFoundEntityException('Member', $email);
         }
         if ($member->EmailVerified) {
             throw new EntityValidationException('Member already verified!');
         }
         $sender_service = new MemberRegistrationSenderService();
         $sender_service->send($member);
     });
 }
 function SaveProfile($data, $form)
 {
     //Check for a logged in member
     if ($CurrentMember = Member::currentUser()) {
         //Check for another member with the same email address
         if (Member::get()->filter(array('Email' => Convert::raw2sql($data['Email']), 'ID:not' => $CurrentMember->ID))->count() > 0) {
             $form->addErrorMessage("Email", 'Sorry, that email address already exists.', "bad");
             Session::set("FormInfo.Form_EditProfileForm.data", $data);
             return $this->redirect($this->Link('?error=1'));
         } else {
             // Clean up bio
             if ($data["Bio"]) {
                 $config = HTMLPurifier_Config::createDefault();
                 // Remove any CSS or inline styles
                 $config->set('CSS.AllowedProperties', array());
                 $purifier = new HTMLPurifier($config);
                 $cleanedBio = $purifier->purify($data["Bio"]);
             }
             $form->saveInto($CurrentMember);
             if (isset($cleanedBio)) {
                 $CurrentMember->Bio = $cleanedBio;
             }
             if ($data['Gender'] == 'Specify') {
                 $CurrentMember->Gender = $data['GenderSpecify'];
             }
             if ($CurrentMember->isChanged('Email')) {
                 $sender = new MemberRegistrationSenderService();
                 $sender->send($CurrentMember->resetConfirmation());
             }
             $CurrentMember->write();
             $speaker = PresentationSpeaker::get()->filter('MemberID', $CurrentMember->ID)->first();
             if ($speaker) {
                 if ($data['ReplaceName'] == 1) {
                     $speaker->FirstName = $data['FirstName'];
                 }
                 if ($data['ReplaceSurname'] == 1) {
                     $speaker->Surname = $data['Surname'];
                 }
                 if ($data['ReplaceBio'] == 1) {
                     $speaker->Bio = $data['Bio'];
                 }
                 $speaker->write();
             }
             // If they do not have a photo uploaded, but they have provided a twitter URL, attempt to grab a photo from twitter
             if ($CurrentMember->TwitterName && !$CurrentMember->Photo()->Exists()) {
                 $this->ProfilePhotoFromTwitter($CurrentMember);
             }
             return $this->redirect($this->Link('?saved=1'));
         }
     } else {
         return Security::PermissionFailure($this->controller, 'You must be <a href="/join">registered</a> and logged in to edit your profile:');
     }
 }