public static function handleRegistrationRequest($overrideFields = array()) { if ($_SESSION['User']) { return static::throwError('You are already logged in. Please log out if you need to register a new account.'); } if (!static::$enableRegistration) { return static::throwError('Sorry, self-registration is not currently available. Please contact an administrator.'); } $filteredRequestFields = array_intersect_key($_REQUEST, array_flip(static::$registrationFields)); $additionalErrors = array(); if (is_callable(static::$createUser)) { $User = call_user_func_array(static::$createUser, array(&$filteredRequestFields, &$additionalErrors)); } else { $className = User::getStaticDefaultClass(); $User = new $className(); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { // save person fields $User->setFields(array_merge($filteredRequestFields, $overrideFields)); if (!empty($_REQUEST['Password'])) { $User->setClearPassword($_REQUEST['Password']); } // additional checks if (empty($_REQUEST['Password']) || strlen($_REQUEST['Password']) < $User::$minPasswordLength) { $additionalErrors['Password'] = '******' . $User::$minPasswordLength . ' characters long.'; } elseif (empty($_REQUEST['PasswordConfirm']) || $_REQUEST['Password'] != $_REQUEST['PasswordConfirm']) { $additionalErrors['PasswordConfirm'] = 'Please enter your password a second time for confirmation.'; } // configurable hook if (is_callable(static::$applyRegistrationData)) { call_user_func_array(static::$applyRegistrationData, array($User, $_REQUEST, &$additionalErrors)); } // validate if ($User->validate() && empty($additionalErrors)) { // save store $User->save(); // upgrade session $GLOBALS['Session'] = $GLOBALS['Session']->changeClass('UserSession', array('PersonID' => $User->ID)); // send welcome email Emergence\Mailer\Mailer::sendFromTemplate($User->EmailRecipient, 'registerComplete', array('User' => $User)); if (is_callable(static::$onRegisterComplete)) { call_user_func(static::$onRegisterComplete, $User, $_REQUEST); } return static::respond('registerComplete', array('success' => true, 'data' => $User)); } if (count($additionalErrors)) { $User->addValidationErrors($additionalErrors); } // fall through back to form if validation failed } else { // apply overrides to phantom $User->setFields($overrideFields); } return static::respond('register', array('success' => false, 'data' => $User)); }
public static function handleContactRequest() { // get optional subform name $subform = static::shiftPath(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { // validate $Validator = new RecordValidator($_REQUEST); foreach (static::$validators as $validatorConfig) { // execute callable validator if (is_callable($validatorConfig)) { $validatorConfig($Validator, $subform); } else { if (!empty($validatorConfig['subforms']) && is_array($validatorConfig['subforms']) && (!$subform || !in_array($subform, $validatorConfig['subforms']))) { // skip if validator specific to other subforms continue; } $Validator->validate($validatorConfig); } } if (!$Validator->hasErrors()) { // save to database $Submission = new ContactSubmission::$defaultClass(); $Submission->Data = array_diff_key($_REQUEST, array_flip(static::$excludeFields)); $Submission->Subform = $subform; $Submission->save(); // generate email report if (!empty(static::$emailTo)) { $headers = array(); if (!empty($_REQUEST['Email']) && Validators::email($_REQUEST['Email'])) { $headers['Reply-To'] = $_REQUEST['Email']; } Emergence\Mailer\Mailer::sendFromTemplate(static::$emailTo, 'staffNotice', array('Submission' => $Submission, 'formatters' => static::$formatters), array('Headers' => $headers)); } // respond success return static::respond('contactSubmitted', array('success' => true, 'subform' => $subform)); } } return static::respond('contact', array('validationErrors' => isset($Validator) ? $Validator->getErrors() : array(), 'subform' => $subform)); }
public function sendEmail($email) { return Emergence\Mailer\Mailer::sendFromTemplate($email, static::$emailTemplate, array('Token' => $this)); }