static public function isValidEmail( $email ) { $v = new sfValidatorEmail(); try { $email = $v->clean( $email ); return true; } catch (sfValidatorError $e) { return false; } }
public function executeSubscribe(sfWebRequest $request) { $this->forward404Unless($request->isXmlHttpRequest()); $email = $request->getParameter('email'); $validator = new sfValidatorEmail(); $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8'); try { $validator->clean($email); $MailChimp = new MailChimp(sfConfig::get('app_mailchimp_api_key')); $result = $MailChimp->call('lists/subscribe', array('id' => sfConfig::get('app_mailchimp_list_id'), 'email' => array('email' => $email), 'merge_vars' => array(), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false)); return $this->renderText(json_encode(array('status' => 'ok'))); } catch (sfValidatorError $e) { return $this->renderText(json_encode(array('status' => 'invalid'))); } }
protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $con = $databaseManager->getDatabase($options['connection'])->getConnection(); if (isset($options['email'])) { $validatorEmail = new sfValidatorEmail(); try { $options['email'] = $validatorEmail->clean($options['email']); } catch (Exception $e) { throw new sfCommandException('The email is invalid.'); } $emails = array('sf_plop_messaging_from_email', 'sf_plop_messaging_to_email'); foreach ($emails as $email) { sfPlopConfigPeer::addOrUpdate($email, $options['email'], $con); } } if (isset($options['email'])) { $validatorName = new sfValidatorString(); try { $options['name'] = $validatorName->clean($options['name']); } catch (Exception $e) { throw new sfCommandException('The name is invalid.'); } $names = array('sf_plop_messaging_from_name', 'sf_plop_messaging_to_name'); foreach ($names as $name) { sfPlopConfigPeer::addOrUpdate($name, $options['name'], $con); } } if (isset($options['username'])) { $user = sfGuardUserQuery::create()->findOneByUsername($options['username']); if ($user) { if (isset($options['email'])) { $user->getProfile()->setEmail($options['email']); } $names = explode(' ', $options['name']); $firstName = $names[0]; unset($names[0]); $lastName = implode(' ', $names); $user->getProfile()->setFirstName($firstName); $user->getProfile()->setLastName($lastName); $user->getProfile()->save(); } else { throw new sfCommandException('There is no user whith username "' . $options['username'] . '".'); } } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $emailValidator = new sfValidatorEmail(array('required' => false), array('invalid' => 'Email must be valid')); $options['email'] = $emailValidator->clean($options['email']); $databaseManager = new sfDatabaseManager($this->configuration); $conn = $databaseManager->getDatabase('doctrine')->getDoctrineConnection(); $manager = Doctrine_Manager::getInstance(); // Properties in databases.yml $this->connectionProperties = array_merge($conn->getOptions(), $manager->parsePdoDsn($conn->getOption('dsn'))); switch ($this->connectionProperties['scheme']) { case 'mysql': $this->doMysql($arguments, $options); break; default: throw new sfException(sprintf("Connection scheme '%s' not supported", $this->connectionProperties['scheme'])); } }
protected function doClean($value) { if (!is_string($value)) { throw new sfValidatorError($this, 'The value is not a string'); } $lines = explode("\r\n", $value); $players = array(); $validator = new sfValidatorEmail(); foreach ($lines as $line) { $parts = explode(":", $line); if (count($parts) != 2) { throw new sfValidatorError($this, 'Invalid format'); } $email = $validator->clean($parts[1]); $players[$email] = $parts[0]; } return $players; }
public function exist_contact_list($list, $email) { $resp = false; $list_return = array(); if (count($list) > 0) { $vEmail = new sfValidatorEmail(array('required' => true)); for ($i = 0; $i < count($list); $i++) { try { $vEmail->clean(strtolower(trim($list[$i]))); if (strtolower(trim($list[$i])) == $email) { $resp = true; } else { $list_return[] = strtolower(trim($list[$i])); } } catch (sfValidatorError $exc) { } } return array('success' => $resp, 'list' => $list_return); } else { return array('success' => $resp, 'list' => $list_return); } }
public function executeInviteWebmail($request) { $errors = null; if ($request->isMethod('post')) { $this->wbForm = new InviteWebmailForm(array('provider' => 'yahoo')); $this->wbForm->bind($request->getParameter('invite')); if ($this->wbForm->isValid()) { // fetch contacts $fetchURL = sprintf(sfConfig::get('app_importer_url'), $this->wbForm->getValue('provider')); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $fetchURL); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='******'username')) . '&password='******'password'))); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); $contacts = @unserialize($result); // parse emails $this->contacts = array(); if ($contacts) { foreach ((array) $contacts as $contact) { // validate email try { $val = new sfValidatorEmail(array('required' => true, 'trim' => true)); $email = $val->clean($contact["contacts_email"]); $this->contacts[] = array_merge(InvitePeer::splitName(trim($contact["contacts_name"])), array("email" => $email)); } catch (sfValidatorError $e) { // do nothing } } } if (!count($this->contacts)) { $errors[] = "- No contacts were found, please check your login details"; } } else { // get errors into array if ($this->wbForm["username"]->hasError()) { $errors[] = "- " . $this->wbForm["username"]->getError(); } if ($this->wbForm["password"]->hasError()) { $errors[] = "- " . $this->wbForm["password"]->getError(); } if ($this->wbForm["provider"]->hasError() && !$this->wbForm["username"]->hasError() && !$this->wbForm["password"]->hasError()) { $errors[] = "- " . $this->wbForm["provider"]->getError(); } } } $this->errors = $errors; }
public function executeRegister_user(sfWebRequest $request) { $email = $request->getParameter('txtEmail'); $firt_name = $request->getParameter('txtNombre'); $last_name = $request->getParameter('txtApellidos'); $password = $request->getParameter('txtPassword'); $password_repeat = $request->getParameter('txt-password-repeat'); //validaciones respectivas $vEmail = new sfValidatorEmail(array('required' => true)); $vString = new sfValidatorString(array('required' => true)); try { $vEmail->clean(strtolower(trim($email))); } catch (sfValidatorError $exc) { return sfView::ERROR; } try { $vString->clean(strtolower(trim($firt_name))); } catch (sfValidatorError $exc) { return sfView::ERROR; } try { $vString->clean(strtolower(trim($last_name))); } catch (sfValidatorError $exc) { return sfView::ERROR; } if ($password != $password_repeat) { return sfView::ERROR; } /*convierto los espacios en blanco en + para que no suceda * algun error al usar el web-service */ $email = str_replace(' ', '+', $email); $firt_name = str_replace(' ', '+', $firt_name); $last_name = str_replace(' ', '+', $last_name); try { $conection = Propel::getConnection(); $conection->beginTransaction(); $new_user = new UserSc(); $new_user->setEmail($email); $new_user->setPassword($password); $new_user->setFlag('1'); $new_user->save(); //procedo a registrar al usuario en practil $lib = new practil_lib(); $url = $lib->url_practil_registrar_user($firt_name, $last_name, md5($password), $email, '1'); //si la url se forma correctamente if ($url != null) { $respuesta_registrar = file_get_contents($url); $decode = json_decode($respuesta_registrar); $codigo_respuesta = $decode->{'success'}; //si el registro en practil es correcto if ($codigo_respuesta) { $new_user->setProfile($decode->{'accountpk'}); $new_user->save(); $conection->commit(); $this->send_mail_scoredcard($decode->{'stoken'}, $new_user->getEmail()); return sfView::SUCCESS; } else { if ($decode->{'code'} == "p-10003") { $respt = array('firtname' => $firt_name, 'lastname' => $last_name, 'email' => $email, 'password' => $password, 'message' => 'el e-mail ya se encuentra registrado!'); $message_sign_in = $this->getUser()->setAttribute('message_sign_in', $respt); $conection->rollBack(); $this->redirect('@homepage'); } else { if ($decode->{'code'} == "p-20009") { $respt = array('firtname' => $firt_name, 'lastname' => $last_name, 'email' => $email, 'password' => $password, 'message' => 'el e-mail ya se encuentra asociado a una cuenta!'); $message_sign_in = $this->getUser()->setAttribute('message_sign_in', $respt); $conection->rollBack(); $this->redirect('@homepage'); } else { $this->message = 'error en practil--' . $url . '--'; $conection->rollBack(); return sfView::ERROR; } } } } else { $conection->rollBack(); $this->message = 'error en url'; return sfView::ERROR; } } catch (Exception $e) { $conection->rollBack(); $this->message = 'error en try'; return sfView::ERROR; } }
public function executeToggle(sfWebRequest $request) { $person = PersonPeer::retrieveByPK($this->getUser()->getId()); $html = ''; switch ($request->getParameter('name')) { case 'email_blocked': $person->setEmailBlocked($person->getEmailBlocked() == 1 ? 0 : 1); if ($person->getEmailBlocked() == 1) { $html = 'Yesun-block email'; } else { $html = 'No block email'; } break; case 'email_text_only': $person->setEmailTextOnly($person->getEmailTextOnly() == 1 ? 0 : 1); if ($person->getEmailTextOnly() == 1) { $html = 'Yesset to any'; } else { $html = 'No set to text only'; } break; case 'email': $validator = new sfValidatorEmail(array('required' => true), array('invalid' => 'Email address is invalid: %value%', 'required' => 'Email address is required')); try { $email = $validator->clean($request->getParameter('email')); $person->setEmail($email); $html = $email; } catch (sfValidatorError $e) { $html = '#' . $e->__toString(); } break; case 'email_list': $email_list_person = new EmailListPerson(); $email_list_person->setPersonId($person->getId()); $email_list_person->setListId($request->getParameter('id')); $result = EmailListPersonPeer::doSelectOne($email_list_person->buildCriteria()); if ($result instanceof EmailListPerson) { $result->delete(); } else { $email_list_person->save(); } if ($email_list_person->isNew()) { $html = 'subscribe'; } else { $html = 'un-subscribe'; } break; } $person->save(); return $this->renderText($html); }
</th> <th> <?php echo __('Anrede') ?> </th> </tr> </thead> --> <tbody> <?php foreach ($enrolments as $i => $enrolment): $v = new sfValidatorEmail(); $email = ''; $err = ''; try { $email = $v->clean( $enrolment->getEmail() ); } catch (sfValidatorError $e) { $err = ' error text-error'; // email invalid } ?> <tr class="<?php echo $err ?>"> <td> <?php echo $i+1 ?> </td> <td> <?php echo $enrolment->getName() ?> </td>
<?php /* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new lime_test(11, new lime_output_color()); $v = new sfValidatorEmail(); // ->clean() $t->diag('->clean()'); foreach (array('*****@*****.**', '*****@*****.**', '*****@*****.**') as $url) { $t->is($v->clean($url), $url, '->clean() checks that the value is a valid email'); } foreach (array('example', 'example@', 'example@localhost', 'example@example.com@example.com') as $nonUrl) { try { $v->clean($nonUrl); $t->fail('->clean() throws an sfValidatorError if the value is not a valid email'); $t->skip('', 1); } catch (sfValidatorError $e) { $t->pass('->clean() throws an sfValidatorError if the value is not a valid email'); $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); } }
public function executeEmailBulkQueue(sfWebRequest $request) { $subject = $request->getParameter('subject'); $to = $request->getParameter('recipients'); $sender_email = $request->getParameter('sender_email'); $sender_name = $request->getParameter('sender_name'); $message = $request->getParameter('message'); $send_date = $request->getParameter('send_date'); $priority = $request->getParameter('priority'); $errors = array(); // validate recievers if (empty($to)) { $errors['email'][0] = 'please specify email address'; } else { $recievers = explode(',', $to); $pat = '/^([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,})$/i'; $full_pat = '/^([- a-z0-9]+)\\<(([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,}))\\>$/i'; $emails = array(); foreach ($recievers as $reciever) { $reciever = trim($reciever); if (empty($reciever)) { continue; } if (preg_match($full_pat, $reciever, $matches)) { $emails[$matches[2]] = $matches[1]; } elseif (preg_match($pat, $reciever, $matches)) { $emails[$matches[0]] = ''; } else { if (!isset($errors['email'])) { $errors['email'] = array(); } $errors['email'][] = $reciever . ' is unrecognizable email'; } } } // validate subject if (empty($subject)) { $errors['subject'] = 'subject required'; } // validate send_date if (empty($send_date)) { $errors['send_date'] = 'Send date required'; } // validate sender $v_email = new sfValidatorEmail(array(), array('invalid' => 'please specify email address')); try { $sender_email = $v_email->clean($sender_email); } catch (sfValidatorError $e) { $errors['sender_email'] = $e->__toString(); } // attachments $upload_dir = sfConfig::get('sf_upload_dir') . '/' . 'bulk-email-attachments' . '/'; $files = array(); foreach ($request->getFiles() as $file) { if ($file[0]['error'] != 0) { continue; } if (move_uploaded_file($file[0]["tmp_name"], $upload_dir . $file[0]["name"])) { $files[] = array('path' => $upload_dir, 'name' => $file[0]['name']); } else { //echo '<h1>Error while uploading '.$file[0]["tmp_name"].'/'.$file[0]["name"].' to '.$upload_dir . $file[0]["name"].'</h1>'; $error['attachment'] = 'Error while uploading ' . $file[0]["name"]; } } // catch errors if ($errors) { $this->email_templates = EmailTemplatePeer::getByPersonId($this->getUser()->getId()); $this->errors = $errors; $this->recipients = $to; $this->subject = $subject; $this->sender_email = $sender_email; $this->sender_name = $sender_name; $this->message = $message; $this->priority = $priority; $this->send_date = $send_date; if (!empty($error['attachment'])) { $this->attachement_error = $error['attachment']; } $this->setTemplate('sendBulkQueue'); return sfView::SUCCESS; } $email_letter = new EmailLetter(); $email_letter->setSubject($subject); $email_letter->setSenderEmail($sender_email); $email_letter->setSenderName($sender_name); $email_letter->setBody($message); $email_letter->setAttachFilePath(serialize($files)); $email_letter->setRecipients(implode(',', array_keys($emails))); $email_letter->save(); $email_queue = new EmailQueue(); $email_queue->setPersonId($this->getUser()->getId()); $email_queue->setLetterId($email_letter->getId()); $email_queue->setRequestDate(date('Y-m-d H:i:s', time())); $email_queue->setSendDate($send_date); $email_queue->setPriority($priority); $email_queue->setSendStatus('pending'); $email_queue->save(); /* $this->getComponent('mail', 'sendBulkQueue', array( 'subject' => $subject, 'recievers' => $emails, 'sender' => array($sender_email => $sender_name), 'body' => $message, 'files' => $files, )); */ $this->getUser()->setFlash('success', 'Bulk email have successfully queued!'); $this->redirect($request->getReferer()); }
protected function save($data) { $event = new sfEvent(null, 'op_csv.import_filter_data'); sfContext::getInstance()->getEventDispatcher()->filter($event, $data); $fields = $event->getReturnValue(); $member = new Member(); $memberConfigs = array(); $memberProfiles = array(); foreach ($data as $key => $col) { $field = $this->fields[$key]; if ($field['is_profile']) { $validator = $field['validator']; $memberProfiles[$field['name']] = $validator->clean($col); continue; } else { switch ($field['name']) { case "nickname": $validator = new opValidatorString(array('max_length' => 64, 'trim' => true, 'required' => true)); $member->name = $validator->clean($col); break; case "mail_address": $validator = new sfValidatorEmail(array('trim' => true, 'required' => true)); $address = $validator->clean($col); if (opToolkit::isMobileEmailAddress($address)) { $memberConfigs['mobile_address'] = $address; } $memberConfigs['pc_address'] = $address; break; case "pc_mail_address": $validator = new sfValidatorEmail(array('trim' => true, 'required' => true)); $address = $validator->clean($col); if (opToolkit::isMobileEmailAddress($address)) { throw new opCsvPluginImportException("'pc_mail_address' is mobile address."); } $memberConfigs['pc_address'] = $address; break; case "mobile_mail_address": $validator = new sfValidatorEmail(array('trim' => true, 'required' => true)); $address = $validator->clean($col); if (!opToolkit::isMobileEmailAddress($address)) { throw new opCsvPluginImportException("'mobile_mail_address' is not support mobile address."); } $memberConfigs['mobile_address'] = $address; break; case "password": $validator = new sfValidatorPassword(array('trim' => true, 'required' => true)); $memberConfigs['password'] = $validator->clean($col); break; } } } // check unique for member config foreach ($this->uniqueMemberConfigFields as $name) { if (isset($memberConfigs[$name]) && Doctrine::getTable('MemberConfig')->retrieveByNameAndValue($name, $memberConfigs[$name])) { throw new opCsvPluginImportException("'" . $name . "' duplicated."); } } $member->setIsActive(true); $member->save(); foreach ($memberConfigs as $key => $value) { $member->setConfig($key, $value); } foreach ($memberProfiles as $key => $value) { $profile = $this->field[$key]['profile']; } }
public function executeSendEmail(sfWebRequest $request) { $subject = $request->getParameter('subject'); $to = $request->getParameter('recipients'); $sender_email = $request->getParameter('sender_email'); $sender_name = $request->getParameter('sender_name'); $message = $request->getParameter('message'); $leg_ids = $request->getParameter('leg_ids'); $errors = array(); // validate recievers if (empty($to)) { $errors['email'][0] = 'please specify email address'; $this->getUser()->setFlash('error', 'Please specify email address!'); $this->redirect($request->getReferer()); } else { $recievers = explode(',', $to); $pat = '/^([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,})$/i'; $full_pat = '/^([- a-z0-9]+)\\<(([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,}))\\>$/i'; $emails = array(); foreach ($recievers as $reciever) { $reciever = trim($reciever); //if (empty($reciever)) { continue; } if (preg_match($full_pat, $reciever, $matches)) { $emails[$matches[2]] = $matches[1]; } elseif (preg_match($pat, $reciever, $matches)) { $emails[$matches[0]] = ''; } else { if (!isset($errors['email'])) { $errors['email'] = array(); } $errors['email'][] = $reciever . ' is unrecognizable email'; } } if (count($emails) < 1) { $errors['email'][0] = 'Please check email address'; $this->getUser()->setFlash('error', 'Please check email address!'); $this->redirect($request->getReferer()); } } // function checkEmail($email) { // if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-]) // ↪*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", // $email)){ // list($username,$domain)=split('@',$email); // if(!checkdnsrr($domain,'MX')) { // return false; // } // return true; // } // return false; // } // validate subject if (empty($subject)) { $errors['subject'] = 'subject required'; } // validate sender $v_email = new sfValidatorEmail(array(), array('invalid' => 'please specify email address')); try { if ($sender_email) { $sender_email = $v_email->clean($sender_email); } else { $sender_email = sfConfig::get('app_mailer_mail', '*****@*****.**'); } if (!$sender_name) { $sender_name = sfConfig::get('app_mailer_name', 'AngelFlight Test'); } } catch (sfValidatorError $e) { $errors['sender_email'] = $e->__toString(); $this->getUser()->setFlash('error', 'Please check sender email address!'); $this->redirect($request->getReferer()); } // catch errors if ($errors) { $this->mission_legs = MissionLegPeer::getByMissionLegIds($leg_ids); $this->email_templates = EmailTemplatePeer::getByPersonId($this->getUser()->getId()); } // attachments $files = array(); foreach ($request->getFiles() as $file) { if ($file['error'] != 0) { continue; } $files[] = array('path' => $file['tmp_name'], 'name' => $file['name']); } // add leg information if ($leg_ids) { $mission_legs = MissionLegPeer::getByMissionLegIds($leg_ids); $message .= '<hr/>' . $this->getComponent('mission', 'includedMissionsTemplate', array('mission_legs' => $mission_legs)); } # TODO queue emails instead of directly sending $this->getComponent('mail', 'missionToPilot', array('subject' => $subject, 'recievers' => $emails, 'sender' => array($sender_email => $sender_name), 'body' => $message, 'files' => $files)); $this->getUser()->setFlash('success', 'Bulk email have successfully queued!'); $this->redirect($request->getReferer()); }
/** * Checks if $value is a valid email or if is a valid user. Returns null if none of them. * * @param type $value * @return null|string */ static function isUserOrEmail($value, $returnEmail = false) { $val = new sfValidatorEmail(); try { $val->clean($value); return $returnEmail ? $value : 'email'; } catch (Exception $exc) { $val = new sfValidatorDoctrineChoice(array('model' => 'sfGuardUser', 'column' => 'username')); try { $val->clean($value); if ($returnEmail) { $user = Doctrine_Core::getTable('sfGuardUser')->findOneByUsername($value); return $user->getEmailAddress(); } return 'user'; } catch (Exception $exc) { return false; } } }