Ejemplo n.º 1
0
 public function validateAddPerson()
 {
     $has_errors = false;
     $msg = "Required";
     $type = $this->getRequestParameter('type');
     $person_name = $this->getRequestParameter('event_person_name_' . $type);
     $email = $this->getRequestParameter('event_email_' . $type);
     $validator = new sfStringValidator();
     $validator->initialize($this->getContext(), array('min' => 1));
     $email_validator = new sfEmailValidator();
     $email_validator->initialize($this->getContext());
     if (!$validator->execute($person_name, $msg)) {
         $this->getRequest()->setError('event_person_name_' . $type, 'Required');
         $has_errors = true;
     } elseif (!$email_validator->execute($email, $msg)) {
         $this->getRequest()->setError('event_email_' . $type, 'Invalid email address');
         $has_errors = true;
     }
     if (!$validator->execute($email, $msg)) {
         $this->getRequest()->setError('event_email_' . $type, 'Required');
         $has_errors = true;
     }
     if ($has_errors) {
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 public function executeValidateEmail()
 {
     $myValidator = new sfEmailValidator();
     $myValidator->initialize($this->getContext(), array());
     $value = urldecode($this->getRequestParameter('value'));
     if (!$myValidator->execute($value, $error)) {
         exit(UtilsHelper::Localize('system.frontend.Validate_email_error'));
     }
     exit("ok");
 }
 /**
  * Returns the email from which all emails are sent.
  *
  * @return string
  */
 public static function getFromEmail()
 {
     $from = sfConfig::get('sf_newsletterplugin_from', false);
     if ($from === false || empty($from)) {
         throw new InvalidArgumentException(self::EXCEPTION_NO_SENDER);
     }
     $validator = new sfEmailValidator(null);
     $error = false;
     if (!$validator->execute($from, $error)) {
         throw new InvalidArgumentException(self::EXCEPTION_INVALID_SENDER);
     }
     return $from;
 }
Ejemplo n.º 4
0
 public function validateAdd()
 {
     if ($this->getUser()->isAuthenticated()) {
         return true;
     }
     $name = $this->getRequestParameter('name');
     $email = $this->getRequestParameter('email');
     $emailValidator = new sfEmailValidator();
     $emailValidator->initialize($this->getContext());
     if (!$name) {
         $this->getRequest()->setError('name', 'Please enter your name.');
     }
     if (!$email) {
         $this->getRequest()->setError('email', 'Please enter your email address.');
     } else {
         if (!$emailValidator->execute($email, $error)) {
             $this->getRequest()->setError('email', 'Please enter a valid email address.');
         }
     }
     if ($this->getRequest()->hasErrors()) {
         return false;
     }
     return true;
 }
<?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 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';
require_once $_test_dir . '/../../../../test/unit/sfContextMock.class.php';
$t = new lime_test(28);
$context = sfContext::getInstance();
$v = new sfEmailValidator($context);
// ->execute()
$t->diag('->execute()');
$validEmails = array('*****@*****.**', '*****@*****.**', '*****@*****.**');
$invalidEmails = array('example', 'example@', 'example@localhost', 'example@example.com@example.com');
$validEmailsNotStrict = array('*****@*****.**', '*****@*****.**', '*****@*****.**', 'example@localhost');
$invalidEmailsNotStrict = array('example', 'example@', 'example@example.com@example.com');
$v->initialize($context);
foreach ($validEmails as $value) {
    $error = null;
    $t->ok($v->execute($value, $error), sprintf('->execute() returns true for a valid email "%s"', $value));
    $t->is($error, null, '->execute() doesn\'t change "$error" if it returns true');
}
foreach ($invalidEmails as $value) {
    $error = null;
    $t->ok(!$v->execute($value, $error), sprintf('->execute() returns false for an invalid email "%s"', $value));
    $t->isnt($error, null, '->execute() changes "$error" with a default message if it returns false');
}
Ejemplo n.º 6
0
 public function executeValidateEmail()
 {
     $myValidator = new sfEmailValidator();
     $myValidator->initialize($this->getContext(), array());
     if (!$myValidator->execute(urldecode($this->getRequestParameter('value')), $error)) {
         exit('you must enter a valid email');
     }
     exit("ok");
 }
Ejemplo n.º 7
0
 public function validateAccountCreate()
 {
     // default values
     $result = true;
     $this->termsUrl = "";
     $this->type = "user";
     $this->company = null;
     $session_user = $this->getUser();
     $this->user = $session_user->getSubscriber();
     $request = $this->getRequest();
     if ($company = Document::getParentOf($session_user->getSubscriberId(), "Company")) {
         $this->company = $company;
     }
     if ($this->user) {
         $type = $this->user->getUserType();
         if ($type == 0) {
             $this->type = "company";
         }
     } elseif ($this->getRequestParameter("acc")) {
         $this->type = $this->getRequestParameter("acc");
     }
     if ($this->getRequestParameter('submitted') == "submitted") {
         $culture = $this->getUser()->getCulture();
         $params = $request->getParameterHolder()->getAll();
         foreach ($params as $key => $param) {
             if (!is_array($param)) {
                 ${$key} = trim($param);
             } else {
                 ${$key} = $param;
             }
         }
         /******* COMMON ********/
         /* firstname */
         /*if(empty($firstname))
         		{
         			$request->setError('errfirstname', "Please fill the 'First name' field");
         			$result = false;
         		}*/
         /* end firstname */
         /* e-mail */
         if (!$this->user) {
             if (empty($email)) {
                 $request->setError('erremail', "Please fill the 'Email' field");
                 $result = false;
             } else {
                 $myValidator = new sfEmailValidator();
                 $myValidator->initialize($this->getContext(), array());
                 $email = urldecode($email);
                 if (!$myValidator->execute($email, $error)) {
                     $request->setError('erremail', "This email is not valid");
                     $result = false;
                 } else {
                     if (!$this->user) {
                         $c = new Criteria();
                         $c->add(UserPeer::LOGIN, $email, Criteria::EQUAL);
                         $c1 = $c->getNewCriterion(UserPeer::LOGIN, $email, Criteria::EQUAL);
                         $c2 = $c->getNewCriterion(UserPeer::EMAIL, $email, Criteria::EQUAL);
                         $c1->addOr($c2);
                         $c->add($c1);
                         $user = UserPeer::doSelectOne($c);
                         if ($user) {
                             $request->setError('erremail', "Your email already exists in our database");
                             $result = false;
                         }
                     }
                 }
             }
         }
         /* end e-mail */
         /* pass */
         /*if(empty($password) && !$this->user)
         		{
         		$request->setError('errpassword', "Please fill the 'Password' field");
         		$result = false;
         		}
         		else
         		{
         		if(strlen($password) < 4 && !$this->user)
         		{
         		$request->setError('errpassword', "Your password must be more than 4 chars long");
         		$result = false;
         		}
         		elseif($this->user && strlen($password) > 0 && strlen($password) < 4)
         		{
         		$request->setError('errpassword', "Your password must be more than 4 chars long");
         		$result = false;
         		}
         		elseif(empty($confirmpass) && !$this->user)
         		{
         		$request->setError('errpassword', "Your password confirmation do not match");
         		$result = false;
         		}
         		elseif(empty($confirmpass) && $this->user && strlen($password) > 0)
         		{
         		$request->setError('errpassword', "Your password confirmation do not match");
         		$result = false;
         		}
         		else
         		{
         		if($password != $confirmpass)
         		{
         		$request->setError('errpassword', "Your password confirmation do not match");
         		$result = false;
         		}
         		}
         		}*/
         /* end pass */
         /* phone
         			if(empty($phone))
         			{
         			$request->setError('errphone', "Please fill the 'phone' field");
         			$result = false;
         			}
         			end phone */
         if (!$this->user) {
             /* captcha */
             if (empty($captcha_code)) {
                 $request->setError('errcaptcha_code', "Please fill the 'Verification code' field");
                 $result = false;
             } else {
                 $code = $this->getUser()->getAttribute('captcha_code');
                 if (!$this->user && $code != $captcha_code) {
                     $request->setError('errcaptcha_code', "Wrong verification code");
                     $result = false;
                 }
             }
             /* end captcha */
             /* terms */
             if (empty($terms)) {
                 $request->setError('errterms', "You must accept the terms and conditions");
                 $result = false;
             }
             /* end terms */
         }
         /***** END COMMON *****/
         /******* COMPANY ********/
         if ($this->type == "company") {
             /* label */
             if (empty($label)) {
                 $request->setError('errlabel', "Please fill the 'Company name' field");
                 $result = false;
             }
             /* end label */
             /* country */
             if (empty($country)) {
                 $request->setError('errcountry', "Please fill the 'Country' field");
                 $result = false;
             }
             /* end country */
             /* description */
             if (empty($description)) {
                 $request->setError('errdescription', "Please fill the 'Description' field");
                 $result = false;
             }
             if ($request->getFileSize("logo") > 0) {
                 try {
                     $this->media = Media::upload('logo', "upload", array("image/gif", "image/png", "image/jpeg", "image/pjpeg", "image/x-png"));
                     if ($this->media && $this->media->IsImage()) {
                         $this->media->resizeImage(null, null, 800);
                         $this->media->resizeImage("thumbs", null, 100);
                     }
                 } catch (Exception $e) {
                     $request->setError('errlogo', UtilsHelper::Localize("media.backend." . $e->getMessage()));
                     $result = false;
                 }
             }
             /* end country */
             /* city
             			if(empty($city))
             			{
             			$request->setError('errcity', "Please fill the 'city' field");
             			$result = false;
             			}
             			end city */
             /* zip
             			if(empty($zip))
             			{
             			$request->setError('errzip', "Please fill the 'zip' field");
             			$result = false;
             			}
             			else
             			{
             			$myValidator = new sfNumberValidator();
             			$myValidator->initialize($this->getContext(), array(
             			'type' 	=>	"int"
             			));
             			if (!$myValidator->execute($zip, $error))
             			{
             			$request->setError('errzip', "The 'zip' field must be a number");
             			$result = false;
             			}
             			}
             			end zip */
             /* address
             			if(empty($address))
             			{
             			$request->setError('erraddress', "Please fill the 'adress' field");
             			$result = false;
             			}
             			end address */
         }
         /***** END COMPANY *****/
         /******** USER *********/
         if ($this->type == "user" && $request->getFileSize("cv") > 0) {
             try {
                 $this->media = Media::upload('cv', "upload", array("application/rtf", "application/msword", "text/plain", "text/richtext", "text/rtf", "application/pdf", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.oasis.opendocument.text", "text/html"));
             } catch (Exception $e) {
                 $request->setError('errcv', UtilsHelper::Localize("media.backend." . $e->getMessage()));
                 $result = false;
             }
         }
         /****** END USER *******/
     }
     return $result;
 }
Ejemplo n.º 8
0
 public function validateResult()
 {
     if ($this->getRequestParameter("codeid")) {
         return true;
     }
     $result = true;
     if ($this->getRequestParameter('newsletter_email')) {
         $email = trim($this->getRequestParameter('newsletter_email'));
         if ($email == "") {
             $this->getRequest()->setError('newsletter_email', "Please enter your email");
             $result = false;
         } else {
             $myValidator = new sfEmailValidator();
             $myValidator->initialize($this->getContext(), array());
             if (!$myValidator->execute(urldecode($email), $error)) {
                 $this->getRequest()->setError('newsletter_email', "Please enter your email");
                 $result = false;
             } else {
                 $c = new Criteria();
                 $c->add(SubscriberPeer::EMAIL, $email);
                 $c->add(SubscriberPeer::PUBLICATION_STATUS, UtilsHelper::STATUS_ACTIVE);
                 $user = SubscriberPeer::doSelectOne($c);
                 if ($user) {
                     $this->getRequest()->setError('newsletter_email', "Email alreday exists!");
                     $result = false;
                 }
             }
         }
     }
     return $result;
 }
Ejemplo n.º 9
0
 public function validateUpdate()
 {
     $id = $this->getRequestParameter('id');
     $name = $this->getRequestParameter('name');
     $email = $this->getRequestParameter('email');
     $captcha = $this->getRequestParameter('captcha');
     $emailValidator = new sfEmailValidator();
     $emailValidator->initialize($this->getContext());
     $captchaValidator = new sfCryptographpValidator();
     $captchaValidator->initialize($this->getContext());
     if (!$this->getUser()->isAuthenticated()) {
         if (!$name) {
             $this->getRequest()->setError('name', 'Please enter your name.');
         }
         if (!$email) {
             $this->getRequest()->setError('email', 'Please enter your email address.');
         } else {
             if (!$emailValidator->execute($email, $error)) {
                 $this->getRequest()->setError('email', 'Please enter a valid email address.');
             }
         }
     }
     if (!$id) {
         if (!$captcha) {
             $this->getRequest()->setError('captcha', 'Please type the code shown.');
         } else {
             if (!$id && !$captchaValidator->execute($captcha, $error)) {
                 $this->getRequest()->setError('captcha', 'The code you entered is not correct.');
             }
         }
     }
     if ($this->getRequest()->hasErrors()) {
         return false;
     }
     return true;
 }