function registerValidators(&$validatorManager, &$controller, &$request, &$user) { $validatorManager->setRequired('account', true, msg('account is required')); $regexValidator = new RegexValidator(); $regexValidator->setParameter('pattern_error', msg('account have invalid character')); $regexValidator->setParameter('pattern', PATTERN_ACCOUNT); $validatorManager->register('account', $regexValidator); $validatorManager->setRequired('password', true, msg('password is required')); $validatorManager->setRequired('email', true, msg('email is required')); $emailValidator = new EmailValidator(); $emailValidator->setParameter('email_error', msg('email is wrong')); $validatorManager->register('email', $emailValidator); }
public function requestEmail() { $email = readline('Input your email:'); $validator = EmailValidator::getInstance(); $valid = $validator->check($email); if ($valid) { $this->user->setEmail($email); } else { echo 'Wrong email. Try again!' . PHP_EOL; $this->requestEmail(); } }
/** * @param SS_HTTPRequest $r */ public function emailattendees(SS_HTTPRequest $r) { $startTime = microtime(true); $summit = Summit::get_most_recent(); $confirm = $r->getVar('confirm'); $limit = $r->getVar('limit'); $attendees = $summit->Attendees(); $totalBeforeLimit = $attendees->count(); $chunkSize = 100; $offset = 0; $appliedLimit = $confirm ? $chunkSize : ($limit ?: 50); $attendees = $attendees->limit($appliedLimit); while ($offset < $totalBeforeLimit) { echo "----- new chunk ({$offset}) ----" . $this->br(); foreach ($attendees->limit($chunkSize, $offset) as $attendee) { if (!EmailValidator::validEmail($attendee->Member()->Email)) { echo $attendee->Member()->Email . " is not a valid email. Skipping" . $this->br(); continue; } $to = $attendee->Member()->Email; $subject = "Rate OpenStack Summit sessions from {$summit->Title}"; $email = EmailFactory::getInstance()->buildEmail('*****@*****.**', $to, $subject); $email->setUserTemplate("rate-summit-sessions-austin"); $email->populateTemplate(['Name' => $attendee->Member()->FirstName]); if ($confirm) { $email->send(); } else { //echo $email->debug(); } echo 'Email sent to ' . $to . ' (' . $attendee->Member()->getName() . ')' . $this->br(); } echo "---- end chunk ({$offset}) ----" . $this->br(); $offset += $chunkSize; } echo $this->br(3) . "Sent a sample of {$appliedLimit} emails out of {$totalBeforeLimit} total" . $this->br(); $endTime = microtime(true); echo "Elapsed time: " . $endTime - $startTime . $this->br(); }
public function edit($params) { if (!isset($params['id']) || !($id = (int) $params['id'])) { throw new Redirect404Exception(); return; } $language = OW::getLanguage(); $config = OW::getConfig(); $sponsor = SPONSORS_BOL_Service::getInstance()->findSponsorById($id); if (!$sponsor->id) { throw new Redirect404Exception(); return; } $sponsorForm = new Form('sponsorForm'); $sponsorForm->setEnctype('multipart/form-data'); $element = new TextField('sponsorName'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'sponsor_name')); $element->setInvitation($language->text('sponsors', 'sponsor_name_desc')); $element->setValue($sponsor->name); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorEmail'); $element->setRequired(true); $validator = new EmailValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_email_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_email')); $element->setInvitation($language->text('sponsors', 'sponsor_email_desc')); $element->setValue($sponsor->email); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorWebsite'); $element->setRequired(true); $validator = new UrlValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_url_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_website')); $element->setInvitation($language->text('sponsors', 'sponsor_website_desc')); $element->setHasInvitation(true); $element->setValue($sponsor->website); $sponsorForm->addElement($element); $element = new TextField('sponsorAmount'); $element->setRequired(true); $minAmount = $config->getValue('sponsors', 'minimumPayment'); $validator = new FloatValidator(0); $validator->setErrorMessage($language->text('sponsors', 'invalid_amount_value')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_payment_amount')); $element->setInvitation($language->text('sponsors', 'admin_payment_amount_desc')); $element->setHasInvitation(true); $element->setValue($sponsor->price); $sponsorForm->addElement($element); $element = new TextField('sponsorValidity'); $element->setRequired(true); $element->setValue($sponsor->validity); $validator = new IntValidator(0); $validator->setErrorMessage($language->text('sponsors', 'invalid_numeric_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsorship_validatity')); $element->setInvitation($language->text('sponsors', 'sponsorship_validatity_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new FileField('sponsorImage'); $element->setLabel($language->text('sponsors', 'sponsorsh_image_file')); $sponsorForm->addElement($element); $element = new Submit('editSponsor'); $element->setValue(OW::getLanguage()->text('sponsors', 'edit_sponsor_btn')); $sponsorForm->addElement($element); if (OW::getRequest()->isPost()) { if ($sponsorForm->isValid($_POST)) { $values = $sponsorForm->getValues(); $allowedImageExtensions = array('jpg', 'jpeg', 'gif', 'png', 'tiff'); $sponsorImageFile = ""; if (isset($_FILES['sponsorImage']) && in_array(UTIL_File::getExtension($_FILES['sponsorImage']['name']), $allowedImageExtensions)) { $backupPath = OW::getPluginManager()->getPlugin('sponsors')->getUserFilesDir() . $_FILES['sponsorImage']['name']; move_uploaded_file($_FILES['sponsorImage']['tmp_name'], $backupPath); $sponsorImageFile = $_FILES['sponsorImage']['name']; } $sponsor->name = $values['sponsorName']; $sponsor->email = $values['sponsorEmail']; $sponsor->website = $values['sponsorWebsite']; $sponsor->price = $values['sponsorAmount']; if (!empty($sponsorImageFile)) { $sponsor->image = $sponsorImageFile; } $sponsor->userId = $sponsor->userId; $sponsor->status = $sponsor->status; $sponsor->validity = $values['sponsorValidity']; if (SPONSORS_BOL_Service::getInstance()->addSponsor($sponsor)) { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_edit_ok')); } else { OW::getFeedback()->error(OW::getLanguage()->text('sponsors', 'sponsor_edit_error')); } } } $this->addForm($sponsorForm); $fields = array(); foreach ($sponsorForm->getElements() as $element) { if (!$element instanceof HiddenField) { $fields[$element->getName()] = $element->getName(); } } $this->assign('formData', $fields); $this->assign('currentLogoImage', OW::getPluginManager()->getPlugin('sponsors')->getUserFilesUrl() . $sponsor->image); $this->setPageHeading(OW::getLanguage()->text('sponsors', 'edit_sponsor_heading')); $this->setPageTitle(OW::getLanguage()->text('sponsors', 'edit_sponsor_heading')); $this->setPageHeadingIconClass('ow_ic_edit'); }
function ThankYou() { $survey = $this->GetCurrentSurvey(); Requirements::javascript('surveys/js/deployment_survey_thankyou_form.js'); if ($survey->BeenEmailed != TRUE && EmailValidator::validEmail($survey->Member()->Email)) { //Send email to submitter $To = $survey->Member()->Email; $Subject = "The OpenStack User Survey: Thank You!"; $email = EmailFactory::getInstance()->buildEmail(DEPLOYMENT_SURVEY_THANK_U_FROM_EMAIL, $To, $Subject); $email->setTemplate('DeploymentSurveyEmail'); $email->populateTemplate($survey); $email->send(); // Set flag in DB that this user has been emailed $survey->BeenEmailed = TRUE; $survey->UpdateDate = SS_Datetime::now()->Rfc2822(); $survey->write(); } return array(); }
public function ImportUsers() { set_time_limit(300); $groupsList = $this->groupViewRepository->GetList(); /** @var GroupItemView[] $groups */ $groups = $groupsList->Results(); $groupsIndexed = array(); foreach ($groups as $group) { $groupsIndexed[$group->Name()] = $group->Id(); } $importFile = $this->page->GetImportFile(); $csv = new UserImportCsv($importFile); $importCount = 0; $messages = array(); $rows = $csv->GetRows(); if (count($rows) == 0) { $this->page->SetImportResult(new CsvImportResult(0, array(), 'Empty file or missing header row')); return; } for ($i = 0; $i < count($rows); $i++) { $row = $rows[$i]; try { $emailValidator = new EmailValidator($row->email); $uniqueEmailValidator = new UniqueEmailValidator($this->userRepository, $row->email); $uniqueUsernameValidator = new UniqueUserNameValidator($this->userRepository, $row->username); $emailValidator->Validate(); $uniqueEmailValidator->Validate(); $uniqueUsernameValidator->Validate(); if (!$emailValidator->IsValid()) { $messages[] = $emailValidator->Messages()[0] . " ({$row->email})"; continue; } if (!$uniqueEmailValidator->IsValid()) { $messages[] = $uniqueEmailValidator->Messages()[0] . " ({$row->email})"; continue; } if (!$uniqueUsernameValidator->IsValid()) { $messages[] = $uniqueUsernameValidator->Messages()[0] . " ({$row->username})"; continue; } $timezone = empty($row->timezone) ? Configuration::Instance()->GetKey(ConfigKeys::DEFAULT_TIMEZONE) : $row->timezone; $password = empty($row->password) ? 'password' : $row->password; $language = empty($row->language) ? 'en_us' : $row->language; $user = $this->manageUsersService->AddUser($row->username, $row->email, $row->firstName, $row->lastName, $password, $timezone, $language, Configuration::Instance()->GetKey(ConfigKeys::DEFAULT_HOMEPAGE), array(UserAttribute::Phone => $row->phone, UserAttribute::Organization => $row->organization, UserAttribute::Position => $row->position), array()); $userGroups = array(); foreach ($row->groups as $groupName) { if (array_key_exists($groupName, $groupsIndexed)) { Log::Debug('Importing user %s with group %s', $row->username, $groupName); $userGroups[] = new UserGroup($groupsIndexed[$groupName], $groupName); } } if (count($userGroups) > 0) { $user->ChangeGroups($userGroups); $this->userRepository->Update($user); } $importCount++; } catch (Exception $ex) { Log::Error('Error importing users. %s', $ex); } } $this->page->SetImportResult(new CsvImportResult($importCount, $csv->GetSkippedRowNumbers(), $messages)); }
<?php require "EmailValidator.php"; require "DatabaseWriter.php"; require "ErrorLogger.php"; $objValidator = new EmailValidator("*****@*****.**"); $objValidator->addObserver(new ErrorLogger(), EmailValidator::EVENT_EMAIL_INVALID); $objValidator->addObserver(new DatabaseWriter(), EmailValidator::EVENT_EMAIL_VALID); $objValidator->validate(); $objValidator->setEmailAddress("not_a_valid_address"); $objValidator->validate();
public function testValidateEmptyValue() { $v = new EmailValidator(); $this->assertTrue($v->validate('')); $this->assertTrue($v->validate(null)); }
function perform() { // extract the data $recipients = $this->_request->getValue("messageRecipient"); $recipientsCc = $this->_request->getValue("messageCc"); $recipientsBcc = $this->_request->getValue("messageBcc"); $text = $this->_request->getValue("messageText"); $subject = $this->_request->getValue("messageSubject"); // check that we've got either a 'to','cc' or 'bcc' if ($recipients == "" && $recipientsCc == "" && $recipientsBcc == "") { // force an error $this->_view = new MailCentreSendMessageView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("mailcentre_error_sending_message")); $this->_form->setFieldValidationStatus("messageRecipient", false); $this->setCommonData(true); } // pre-process some of the data $recipients = str_replace(" ", "", $recipients); $recipientsCc = str_replace(" ", "", $recipientsCc); $recipientsBcc = str_replace(" ", "", $recipientsBcc); // and get the list of recipients $listUnexpanded = explode(",", $recipients); $list = array(); foreach ($listUnexpanded as $recipient) { $result = $this->_expandRecipients($recipient); $list = array_merge($list, $result); } $listCcUnexpanded = explode(",", $recipientsCc); $listCc = array(); foreach ($listCcUnexpanded as $recipient) { $result = $this->_expandRecipients($recipient); $listCc = array_merge($listCc, $result); } $listBccUnexpanded = explode(",", $recipientsBcc); $listBcc = array(); foreach ($listBccUnexpanded as $recipient) { $result = $this->_expandRecipients($recipient); $listBcc = array_merge($listBcc, $result); } // create a mail message that includes all the recipients $message = new EmailMessage(); $val = new EmailValidator(); $totalTo = 0; $totalCc = 0; $totalBcc = 0; foreach ($list as $to) { // add each one of the recipients if ($val->validate($to)) { $message->addTo($to); $totalTo++; } } foreach ($listCc as $cc) { // add each one of the recipients if ($val->validate($cc)) { $message->addCc($cc); $totalCc++; } } foreach ($listBcc as $bcc) { // add each one of the recipients if ($val->validate($bcc)) { $message->addBcc($bcc); $totalBcc++; } } // check that we are really sending the message to somebody if ($totalTo == 0 && $totalCc == 0 && $totalBcc == 0) { // force an error $this->_view = new MailCentreSendMessageView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("mailcentre_error_sending_message")); $this->_form->setFieldValidationStatus("messageRecipient", false); $this->setCommonData(true); } // and now set the subject and body... $message->setSubject($subject); $message->setBody($text); // set the encoding based on the current blog settings $locale =& $this->_blogInfo->getLocale(); $message->setCharset($locale->getCharset()); // and the "from" address $config =& Config::getConfig(); $from = $config->getValue("post_notification_source_address"); $message->setFrom($from); // now send the message $service = new EmailService(); if (!$service->sendMessage($message)) { // if something went wrong, go back to the previous view $this->_view = new MailCentreSendMessageView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("mailcentre_error_sending_message")); // show the view and keep the data that was in the form $this->setCommonData(true); } $recipients = implode(",", $list); $recipientsCc = implode(",", $listCc); $recipientsBcc = implode(",", $listBcc); // if everything went ok, create our own MailMessage object and save it to the database $mailMessage = new MailMessage($subject, $text, $recipients, $recipientsCc, $recipientsBcc); $mailMessages = new MailMessages(); $mailMessages->addMessage($mailMessage); // show the resulting view $this->_view = new MailCentreMessageListView($this->_blogInfo); $this->_view->setSuccessMessage($this->_locale->tr("mailcentre_message_sent_ok")); $this->setCommonData(); return true; }
public function sponsor() { $language = OW::getLanguage(); $config = OW::getConfig(); $sponsorForm = new Form('sponsorForm'); $sponsorForm->setEnctype('multipart/form-data'); $element = new TextField('sponsorName'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'sponsor_name')); $element->setInvitation($language->text('sponsors', 'sponsor_name_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorEmail'); $element->setRequired(true); $validator = new EmailValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_email_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_email')); $element->setInvitation($language->text('sponsors', 'sponsor_email_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorWebsite'); $element->setRequired(true); $validator = new UrlValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_url_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_website')); $element->setInvitation($language->text('sponsors', 'sponsor_website_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); if ($config->getValue('sponsors', 'minimumPayment') > 0) { $element = new TextField('sponsorAmount'); $element->setRequired(true); $element->setValue($config->getValue('sponsors', 'minimumPayment')); $minAmount = $config->getValue('sponsors', 'minimumPayment'); $validator = new FloatValidator($minAmount); $validator->setErrorMessage($language->text('sponsors', 'invalid_sponsor_amount', array('minAmount' => $minAmount))); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_payment_amount')); $element->setInvitation($language->text('sponsors', 'sponsor_payment_amount_desc', array('minAmount' => $minAmount))); $element->setHasInvitation(true); $sponsorForm->addElement($element); } $element = new FileField('sponsorImage'); $element->setLabel($language->text('sponsors', 'sponsorsh_image_file')); $sponsorForm->addElement($element); if ($config->getValue('sponsors', 'minimumPayment') > 0) { $element = new BillingGatewaySelectionField('gateway'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'payment_gatway_selection')); $sponsorForm->addElement($element); } $element = new Submit('becomeSponsor'); $element->setValue(OW::getLanguage()->text('sponsors', 'become_sponsor_btn')); $sponsorForm->addElement($element); if (OW::getRequest()->isPost()) { if ($sponsorForm->isValid($_POST)) { $values = $sponsorForm->getValues(); if (isset($_FILES['sponsorImage']) && in_array(UTIL_File::getExtension($_FILES['sponsorImage']['name']), $this->allowedImageExtensions)) { $backupPath = OW::getPluginManager()->getPlugin('sponsors')->getUserFilesDir() . $_FILES['sponsorImage']['name']; move_uploaded_file($_FILES['sponsorImage']['tmp_name'], $backupPath); $sponsorImageFile = $_FILES['sponsorImage']['name']; } else { $sponsorImageFile = "defaultSponsor.jpg"; } if (isset($values['sponsorAmount']) && $values['gateway']) { $billingService = BOL_BillingService::getInstance(); if (empty($values['gateway']['url']) || empty($values['gateway']['key']) || !($gateway = $billingService->findGatewayByKey($values['gateway']['key']) || !$gateway->active)) { OW::getFeedback()->error($language->text('base', 'billing_gateway_not_found')); $this->redirect(); } $productAdapter = new SPONSORS_CLASS_SponsorProductAdapter(); $sale = new BOL_BillingSale(); $sale->pluginKey = 'sponsors'; $sale->entityDescription = $language->text('sponsors', 'sponsor_payment_gateway_text'); $sale->entityKey = $productAdapter->getProductKey(); $sale->entityId = time(); $sale->price = floatval($values['sponsorAmount']); $sale->period = null; $sale->userId = OW::getUser()->getId() ? OW::getUser()->getId() : 0; $sale->recurring = 0; $extraData = array(); $extraData['sponsorName'] = $values['sponsorName']; $extraData['sponsorEmail'] = $values['sponsorEmail']; $extraData['sponsorWebsite'] = $values['sponsorWebsite']; $extraData['sponsorAmount'] = $values['sponsorAmount']; $extraData['sponsorImage'] = $sponsorImageFile; $extraData['status'] = $config->getValue('sponsors', 'autoApprove') == '1' ? 1 : 0; $extraData['validity'] = $config->getValue('sponsors', 'sponsorValidity'); $sale->setExtraData($extraData); $saleId = $billingService->initSale($sale, $values['gateway']['key']); if ($saleId) { $billingService->storeSaleInSession($saleId); $billingService->setSessionBackUrl($productAdapter->getProductOrderUrl()); OW::getApplication()->redirect($values['gateway']['url']); } } else { $sponsor = new SPONSORS_BOL_Sponsor(); $sponsor->name = $values['sponsorName']; $sponsor->email = $values['sponsorEmail']; $sponsor->website = $values['sponsorWebsite']; $sponsor->price = 0; $sponsor->image = $sponsorImageFile; $sponsor->userId = OW::getUser()->getId() ? OW::getUser()->getId() : 0; $sponsor->status = $config->getValue('sponsors', 'autoApprove') == '1' ? 1 : 0; $sponsor->validity = $config->getValue('sponsors', 'sponsorValidity'); $sponsor->timestamp = time(); if (SPONSORS_BOL_Service::getInstance()->addSponsor($sponsor)) { if ($sponsor->status == 1) { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_live_notification')); } else { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_live_notification_after_approval')); } } else { OW::getFeedback()->error(OW::getLanguage()->text('sponsors', 'sponsor_add_error')); } } } } $this->addForm($sponsorForm); $fields = array(); foreach ($sponsorForm->getElements() as $element) { if (!$element instanceof HiddenField) { $fields[$element->getName()] = $element->getName(); } } $this->assign('formData', $fields); $this->setPageHeading(OW::getLanguage()->text('sponsors', 'become_sponsor_heading')); $this->setPageTitle(OW::getLanguage()->text('sponsors', 'become_sponsor_title')); $this->setPageHeadingIconClass('ow_ic_gear_wheel'); }