Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 public function sendEmailInvitationsEvent($runData)
 {
     $pl = $runData->getParameterList();
     $user = $runData->getUser();
     $site = $runData->getTemp("site");
     $json = new JSONService(SERVICES_JSON_LOOSE_TYPE);
     $addresses = $json->decode($pl->getParameterValue("addresses"));
     $message = $pl->getParameterValue("message");
     // check if data is valid
     if (count($addresses) > 200) {
         throw new ProcessException(_("You should not send more than 200 invitations at once."));
     }
     foreach ($addresses as $address) {
         $email = trim($address[0]);
         $name = trim($address[1]);
         if (!preg_match("/^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)+\$/", $email) || strlen($email) > 70 || strlen($email) == 0) {
             throw new ProcessException(sprintf(_('Email "%s" is not valid.'), htmlspecialchars($email)), "bad_email");
         }
         if (preg_match(';://;', $name) || preg_match(';\\.www;i', $name) || strlen8($name) > 50 || strlen8($name) == 0) {
             throw new ProcessException(sprintf(_('Recipient\'s name "%s" is not valid.'), htmlspecialchars($name)), "bad_name");
         }
         //check if "email" is not already a member of this site...
         $q = " SELECT * FROM member, ozone_user WHERE member.site_id='" . $site->getSiteId() . "' AND ozone_user.name='" . db_escape_string($email) . "' AND member.user_id = ozone_user.user_id LIMIT 1";
         $c = new Criteria();
         $c->setExplicitQuery($q);
         $m = DB_MemberPeer::instance()->selectOne($c);
         if ($m) {
             throw new ProcessException(sprintf(_('User with the email address "%s" is already a member of this Site. Remove him from the list and send invitations again.'), htmlspecialchars($email)), 'aleady_member');
         }
         // check if not sent already to this address.
         $c = new Criteria();
         $c->add("email", $email);
         $c->add("site_id", $site->getSiteId());
         $ii = DB_EmailInvitationPeer::instance()->selectOne($c);
         if ($ii) {
             throw new ProcessException(sprintf(_('User with the email address "%s" has been already invited to this Site. Remove him from the list and send invitations again. If you want to resend an invitation please rather look at the history of sent invitations.'), htmlspecialchars($email)), 'aleady_member');
         }
     }
     if (preg_match(';://;', $message) || preg_match(';www\\.;i', $message)) {
         throw new ProcessException(_('The message should not contain any links to websites.'), "bad_message");
     }
     if ($message != "" && strlen($message) > 1000) {
         throw new ProcessException(_('The message seems to be too long. Max 1000 characters are allowed.'), "bad_message");
     }
     // now prepare invitation and send!
     $db = Database::connection();
     foreach ($addresses as $address) {
         $email = trim($address[0]);
         $name = trim($address[1]);
         $db->begin();
         // each invitation makes a separate transaction
         $hash = substr(md5($name . $email) . time(), 0, 20);
         $inv = new DB_EmailInvitation();
         $inv->setHash($hash);
         $inv->setEmail($email);
         $inv->setName($name);
         $inv->setUserId($user->getUserId());
         $inv->setSiteId($site->getSiteId());
         $inv->setMessage($message);
         $inv->setDate(new ODate());
         if ($address[2]) {
             $inv->setToContacts(true);
         }
         // prepare and send email
         $profile = $user->getProfile();
         $oe = new OzoneEmail();
         $oe->addAddress($email);
         $oe->setSubject(sprintf(_("[%s] %s invites you to join!"), GlobalProperties::$SERVICE_NAME, $user->getNickName()));
         $oe->contextAdd('user', $user);
         $oe->contextAdd('profile', $profile);
         $oe->contextAdd('hash', $hash);
         $oe->contextAdd("site", $site);
         $oe->contextAdd("message", $message);
         $oe->contextAdd('name', $name);
         $oe->setBodyTemplate('MembershipEmailInvitation');
         if (!$oe->Send()) {
             $inv->setDelivered(false);
         } else {
             $inv->setDelivered(true);
         }
         $inv->save();
         $db->commit();
     }
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 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);
     }
 }