public function step1Event($runData) { $pl = $runData->getParameterList(); $email = $pl->getParameterValue("email", "AMODULE"); if ($email == null || $email == '') { throw new ProcessException(_("Email must be provided."), "no_email"); } $email = trim(CryptUtils::rsaDecrypt($email)); $email = preg_replace("/^__/", '', $email); if ($email == null || $email == '') { throw new ProcessException(_("Email must be provided."), "no_email"); } if (preg_match("/^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)+\$/", $email) == 0) { throw new ProcessException(_("Valid email must be provided."), "no_email"); } // check for users with the email $c = new Criteria(); $c->add("lower(email)", strtolower($email)); $user = DB_OzoneUserPeer::instance()->selectOne($c); if ($user == null) { throw new ProcessException(_("This email can not be found in our database."), "no_email"); } // generate code srand((double) microtime() * 1000000); $string = md5(rand(0, 9999)); $evcode = substr($string, 2, 6); //send a confirmation email to the user. $oe = new OzoneEmail(); $oe->addAddress($email); $oe->setSubject(sprintf(_("%s - password recovery"), GlobalProperties::$SERVICE_NAME)); $oe->contextAdd("user", $user); $oe->contextAdd("email", $email); $oe->contextAdd('revcode', $evcode); $oe->setBodyTemplate('PasswordRecoveryEmail'); if (!$oe->Send()) { throw new ProcessException(_("The email can not be sent to this address."), "no_email"); } $runData->sessionAdd("revcode", $evcode); $runData->sessionAdd("prUserId", $user->getUserId()); $runData->contextAdd("email", $email); }
public function resendEmailInvitationEvent($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $invitationId = $pl->getParameterValue("invitationId"); $message2 = trim($pl->getParameterValue("message")); $c = new Criteria(); $c->add("invitation_id", $invitationId); $c->add("site_id", $site->getSiteId()); $inv = DB_EmailInvitationPeer::instance()->selectOne($c); if (!$inv) { throw new ProcessException(_("Invitation could not be found."), "no_invitation"); } if ($inv->getAttempts() >= 3) { throw new ProcessException(_("You can not send more than 3 copies of the invitation.")); } if ($message2 == "") { throw new ProcessException(_('Message should not be empty')); } if (preg_match(';://;', $message2) || preg_match(';\\.www;i', $message2)) { throw new ProcessException(_('The message should not contain any links to websites.'), "bad_message"); } if ($message2 != "" && strlen($message2) > 1000) { throw new ProcessException(_('The message seems to be too long. Max 1000 characters are allowed.'), "bad_message"); } $db = Database::connection(); $db->begin(); // prepare and send email $user = $runData->getUser(); $profile = $user->getProfile(); $oe = new OzoneEmail(); $oe->addAddress($inv->getEmail()); $oe->setSubject(sprintf(_("[%s] %s invites you to join! (reminder)"), GlobalProperties::$SERVICE_NAME, $user->getNickName())); $oe->contextAdd('user', $user); $oe->contextAdd('profile', $profile); $oe->contextAdd('hash', $inv->getHash()); $oe->contextAdd("site", $site); $oe->contextAdd("message", $inv->getMessage()); $oe->contextAdd("message2", $message2); $oe->contextAdd('name', $inv->getName()); $oe->setBodyTemplate('MembershipEmailInvitation'); $res = $oe->send(); if (!$res) { throw new ProcessException("Email to this recipient could not be sent for some reason."); } $inv->setAttempts($inv->getAttempts() + 1); $inv->save(); $db->commit(); }
public function signEvent($runData) { require WIKIDOT_ROOT . '/php/unclassified/country_codes.php'; $site = $runData->getTemp("site"); $pl = $runData->getParameterList(); $campaignId = $pl->getParameterValue("campaignId"); $db = Database::connection(); $db->begin(); $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->add("deleted", false); $c->add("campaign_id", $campaignId); $camp = DB_PetitionCampaignPeer::instance()->selectOne($c); if (!$camp) { throw new ProcessException(_("The campaign can not be found.")); } if (!$camp->getActive()) { throw new ProcessException(_("This petition campaign is paused.")); } $errors = array(); // prepare the new signature at the same time $pet = new DB_PetitionSignature(); // first and last name $firstName = trim($pl->getParameterValue("firstName")); if (strlen($firstName) == 0) { $errors['firstName'] = _("Please enter your first name."); } elseif (strlen8($firstName) > 64) { $errors['firstName'] = _("First name seems to be too long."); } $lastName = trim($pl->getParameterValue("lastName")); if (strlen($lastName) == 0) { $errors['lastName'] = _("Please enter your last name."); } elseif (strlen8($lastName) > 64) { $errors['lastName'] = _("Last name seems to be too long."); } $pet->setFirstName($firstName); $pet->setLastName($lastName); // address if ($camp->getCollectAddress()) { $address1 = trim($pl->getParameterValue("address1")); $address2 = trim($pl->getParameterValue("address2")); if (strlen($address1) == 0) { $errors['address'] = _("Please enter your address."); } elseif (strlen8($address1) > 100) { $errors['address'] = _("The address seems to be too long."); } if (strlen8($address2) > 100) { $errors['address'] = _("The address seems to be too long."); } $pet->setAddress1($address1); $pet->setAddress2($address2); } //city if ($camp->getCollectCity()) { $city = trim($pl->getParameterValue("city")); if (strlen($city) == 0) { $errors['city'] = _("Please enter the city of residence."); } elseif (strlen8($city) > 64) { $errors['city'] = _("The city name seems to be too long."); } $pet->setCity($city); } //state if ($camp->getCollectState()) { $state = trim($pl->getParameterValue("state")); //}else if (strlen8($state) > 64) { $errors['state'] = _("The name of the state seems to be too long."); } $pet->setState($state); } //zip if ($camp->getCollectZip()) { $zip = trim($pl->getParameterValue("zip")); if (strlen($zip) == 0) { $errors['zip'] = _("Please enter your zip/postal code."); } elseif (strlen8($zip) > 20) { $errors['zip'] = _("The zip/postal code seems to be too long."); } $pet->setZip($zip); } //country if ($camp->getCollectCountry()) { $country = trim($pl->getParameterValue("country")); if (strlen($country) == 0 || !isset($iso3166_country_codes[$country])) { $errors['country'] = _("Please choose your country."); } $pet->setCountryCode($country); $pet->setCountry($iso3166_country_codes[$country]); /* if(strlen($country) == 0){ $errors['country'] = _("Please enter your country."); }elseif(strlen8($country) > 60){ $errors['country'] = _("The name of the country is too long."); } $pet->setCountry($country); */ } //comments if ($camp->getCollectComments()) { $comments = trim($pl->getParameterValue("comments")); if (strlen8($comments) > 300) { $errors['comments'] = _("The comments should not be longer than 300 characters."); } $pet->setComments($comments); } //verify email $email = trim($pl->getParameterValue("email")); if (!preg_match('/^[_a-zA-Z0-9\\-\\+]+(\\.[_a-zA-Z0-9\\-\\+]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)+$/', $email)) { $errors['email'] = _("Please provide a valid email address."); } // check if email is unique for this campaign! if (!$errors['email']) { $c = new Criteria(); $c->add("campaign_id", $camp->getCampaignId()); $c->add("email", $email); $pet0 = DB_PetitionSignaturePeer::instance()->selectOne($c); if ($pet0) { if ($pet0->getConfirmed()) { $errors['email'] = _("This email has been already used for signing the petition."); } else { DB_PetitionSignaturePeer::instance()->deleteByPrimaryKey($pet0->getSignatureId()); } } } $pet->setEmail($email); if (count($errors) > 0) { // there are some errors!!! $runData->ajaxResponseAdd("errors", $errors); throw new ProcessException(_("The form contains some errors."), "form_errors"); } // everything should be ok at this point - finish creating the signature, // save the signature and send a verification email. $pet->setCampaignId($camp->getCampaignId()); $pet->setDate(new ODate()); // generate hash. $hash = substr(md5($email . time()), 0, 20); $pageUnixName = $pl->getParameterValue("petitionUrl"); $pageUnixName = WDStringUtils::toUnixName($pageUnixName); $url = $site->getDomain() . '/' . $pageUnixName; $pet->setConfirmationUrl($url); $oe = new OzoneEmail(); $oe->addAddress($email); $oe->setSubject(_("Petition confirmation")); $oe->contextAdd('firstName', $firstName); $oe->contextAdd('lastName', $lastName); $oe->contextAdd('hash', $hash); $oe->contextAdd("site", $site); $oe->contextAdd("siteName", $site->getName()); $oe->contextAdd("url", $url); $oe->contextAdd("campaign", $camp); $oe->contextAdd("campaignName", $camp->getName()); $oe->contextAdd("sig", $pet); $oe->setBodyTemplate('wiki/petition/PetitionConfirmation'); if (!$oe->Send()) { throw new ProcessException(_("Confirmation email can not be delivered to the specified address.")); } $pet->setConfirmationHash($hash); $pet->setConfirmationUrl('/' . $pageUnixName); $pet->save(); $db->commit(); $runData->setModuleTemplate("extra/petition/ConfirmationSentModule"); $runData->sessionAdd("keep", true); }
public function handleUser($user) { $db = Database::connection(); $db->begin(); $c = new Criteria(); $c->add("user_id", $user->getUserId()); $c->add("notify_email", true); $c->addOrderAscending("notification_id"); $nots = DB_NotificationPeer::instance()->select($c); if (count($nots) == 0) { $db->commit(); return; } if (count($nots) > 0) { $q = "UPDATE notification SET notify_email=FALSE " . "WHERE user_id='" . $user->getUserId() . "' AND " . "notify_email = TRUE"; $db->query($q); } // set language $lang = $user->getLanguage(); OZONE::getRunData()->setLanguage($lang); $GLOBALS['lang'] = $lang; // and for gettext too: switch ($lang) { case 'pl': $glang = "pl_PL"; break; case 'en': $glang = "en_US"; break; } putenv("LANG={$glang}"); putenv("LANGUAGE={$glang}"); setlocale(LC_ALL, $glang . '.UTF-8'); $nots2 = array(); foreach ($nots as &$not) { if ($not->getType() == "new_private_message") { // check if the message is read or still new $extra = $not->getExtra(); $pm = DB_PrivateMessagePeer::instance()->selectByPrimaryKey($extra['message_id']); if ($pm && $pm->getFlagNew()) { $body = $not->getBody(); $body = preg_replace('/<br\\/>Preview.*$/sm', '', $body); $body = preg_replace(';You have.*?<br/>;sm', '', $body); $not->setBody($body); $nots2[] = $not; } } else { $nots2[] = $not; } } $count = count($nots2); // now send an email $oe = new OzoneEmail(); $oe->addAddress($user->getName()); $oe->setSubject(sprintf(_("%s Account Notifications"), GlobalProperties::$SERVICE_NAME)); $oe->contextAdd('user', $user); $oe->contextAdd('notifications', $nots2); $oe->contextAdd('count', $count); $oe->setBodyTemplate('DigestEmail'); if (!$oe->send()) { throw new ProcessException("The email can not be sent to address " . $user->getName(), "email_failed"); } $db->commit(); }
public function changeEmail1Event($runData) { $pl = $runData->getParameterList(); $email = $pl->getParameterValue("email", "AMODULE"); if ($email == null || $email == '') { throw new ProcessException(_("Email must be provided."), "no_email"); } if (preg_match("/^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)+\$/", $email) == 0) { throw new ProcessException(_("Valid email must be provided."), "no_email"); } // check for users with the email $c = new Criteria(); $c->add("email", $email); $user = DB_OzoneUserPeer::instance()->selectOne($c); if ($user !== null) { throw new ProcessException(_("An user with this email already exists. Emails must be unique."), "form_error"); } // generate code srand((double) microtime() * 1000000); $string = md5(rand(0, 9999)); $evcode = substr($string, 2, 6); //send a confirmation email to the user. $oe = new OzoneEmail(); $oe->addAddress($email); $oe->setSubject(sprintf(_("%s - email address change"), GlobalProperties::$SERVICE_NAME)); $oe->contextAdd("user", $runData->getUser()); $oe->contextAdd("email", $email); $oe->contextAdd('evcode', $evcode); $oe->setBodyTemplate('ChangeEmailVerification'); if (!$oe->Send()) { throw new ProcessException(_("The email can not be sent to this address."), "form_error"); } $runData->sessionAdd("chevcode", $evcode); $runData->sessionAdd("ch-nemail", $email); $runData->contextAdd("email", $email); }
public function sendEmailVerEvent($runData) { $data = $runData->sessionGet("ca_data"); $email = $data['email']; $name = $data['name']; //generate the email verification code $evcode = $runData->sessionGet('evcode'); if ($evcode == null) { srand((double) microtime() * 1000000); $string = md5(rand(0, 9999)); $evcode = substr($string, 2, 6); } //send a confirmation email to the user. $oe = new OzoneEmail(); $oe->addAddress($email); $oe->setSubject(sprintf(_("%s- email verification"), GlobalProperties::$SERVICE_NAME)); $oe->contextAdd('name', $name); $oe->contextAdd('email', $email); $oe->contextAdd('evcode', $evcode); $oe->setBodyTemplate('RegistrationEmailVerification'); if (!$oe->Send()) { throw new ProcessException(_("The email can not be sent to this address."), "email_failed"); } $runData->sessionAdd('evcode', $evcode); }
public function sendFormEvent($runData) { $pl = $runData->getParameterList(); $values = $pl->getParameterValue("formdata"); $json = new JSONService(SERVICES_JSON_LOOSE_TYPE); $values = $json->decode($values); $site = $runData->getTemp("site"); $fkey = trim($pl->getParameterValue("formdef")); $data = DatabaseStorage::instance()->get($fkey); if (!$data) { throw new ProcessException(_("No form definition found.")); } $fields = $data['fields']; $email = $data['email']; $title = $data['title']; $format = strtolower(trim($data['format'])); if (!in_array($format, array('csv'))) { $format = null; } // parse and validate! $errors = array(); foreach ($fields as &$field) { $name = $field['name']; $value = $values[$field['name']]; $field['value'] = $value; // check if need to validate. any rules? // first, if select, can not be empty if ($field['type'] == "select") { if (!$value) { $errors[$name] = _('Please select an option'); continue; } } if ($field['rules'] && is_array($field['rules'])) { foreach ($field['rules'] as $ruleName => $ruleValue) { switch ($ruleName) { case 'required': if ($value == "") { $errors[$name] = _('Please enter this information'); break 2; } break; case 'minLength': if (strlen8($value) < $ruleValue) { $errors[$name] = _('Value is too short'); break 2; } break; case 'maxLength': if (strlen8($value) > $ruleValue) { $errors[$name] = _('Value is too long'); break 2; } break; case 'match': if (!preg_match($ruleValue, $value)) { $errors[$name] = _('Value is not valid'); break 2; } break; case 'number': if (!is_numeric($value)) { $errors[$name] = _('Value is not numeric'); break 2; } break; case 'minValue': if (!is_numeric($value) || 1 * $value < 1 * $ruleValue) { $errors[$name] = _('Value is too small'); break 2; } break; case 'maxValue': if (!is_numeric($value) || 1 * $value > 1 * $ruleValue) { $errors[$name] = _('Value is too large'); break 2; } break; } } } // fix checkboxes if ($field['type'] == "checkbox") { if (!$value) { $field['value'] = _('No'); } else { $field['value'] = _('Yes'); } } } if (count($errors)) { // "sir, we have some errors here. shit." $runData->ajaxResponseAdd("errors", $errors); throw new ProcessException("Form errors.", "form_errors"); } $title = $title ? $title : sprintf(_("[%s] MailForm form data"), GlobalProperties::$SERVICE_NAME); $oe = new OzoneEmail(); $oe->addAddress($email); $oe->setSubject($title); $oe->contextAdd('fields', $fields); $oe->contextAdd('values', $values); switch ($format) { case 'csv': $emailTemplate = 'wiki/mailform/MailFormCSV'; // fix the values (escape) foreach ($fields as &$field) { $value = $field['value']; if (preg_match("/[,\"\n]/", $value)) { $value = str_replace('"', '""', $value); $value = '"' . $value . '"'; $field['value'] = $value; } } break; default: $emailTemplate = 'wiki/mailform/MailForm'; break; } $oe->setBodyTemplate($emailTemplate); if (!$oe->Send()) { throw new ProcessException(_("The form data could not be sent to the specified email address."), "email_failed"); } // ok, is there any success page? $successPage = $data['successPage']; if ($successPage) { $successPage = WDStringUtils::toUnixName($successPage); $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $successPage); if ($page) { $runData->ajaxResponseAdd("successPage", $successPage); } } if (GlobalProperties::$UI_SLEEP) { sleep(1); } }