-
-
Save PeeHaa/36f02e4b309726e1363c13f2ee6d0477 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
public function register() | |
{ | |
$this->event = Event::find($_POST['event_id']); | |
if ( ! $this->event ) redirect_to(WS_ROOT.Event::BASE_PATH.'/'); | |
if ( ! $this->event->can_Register()) { | |
set_flash('warning', 'This event is unavailable for registration.'); | |
redirect_to($this->event->get_URL()); | |
} | |
if ($this->isCaptchaValid()) { | |
set_flash('warning', 'The reCAPTCHA wasn\'t entered correctly.'); | |
redirect_to($this->event->get_URL()); | |
} | |
$this->sendMail(); | |
set_flash('notice', 'You have successfully registered for this event.'); | |
$this->render('events/thank-you'); | |
} | |
private function isCaptchaValid() | |
{ | |
if ( ENV !== 'production' ) { | |
return true; | |
} | |
$recaptcha = new ReCaptcha\ReCaptcha(NEW_RECAPTCHA_PRIVATE_KEY); | |
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']); | |
if ( $resp->isSuccess() ) { | |
return true; | |
} | |
return false; | |
} | |
private function sendMail() | |
{ | |
$to = (ENV == 'production') ? $this->event->register_email : ERROR_EMAIL_TO; | |
$headers = array( | |
'From' => 'donotreply@'.Site::Current()->domain, | |
'Subject' => 'Event Registration: '.$this->event->title | |
); | |
send_mail($to, $this->buildMailBody($this->event, $_POST['registration']), $headers); | |
} | |
private function buildMailBody($event, $registration) | |
{ | |
$body = 'Date: '. $event->start_datetime . "\n"; | |
foreach($registration as $key => $value) { | |
if (is_array($value)) $value = join("\n", $value); | |
$key = ucwords($key); | |
$body .= $key.': '.$value."\n"; | |
} | |
return $body; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment