protected function doClean($value)
 {
     set_time_limit(0);
     $uploads = new Doctrine_Collection($this->getOption('model'));
     $fileValidator = new sfValidatorFile(array('mime_types' => 'web_images'));
     $descriptionValidator = new sfValidatorString(array('max_length' => 255, 'required' => false, 'trim' => true));
     foreach ($value as $file) {
         $validatedDescription = $descriptionValidator->clean($file['description']);
         if (isset($file['file']) && is_array($file['file']) && $file['file']['tmp_name']) {
             $validatedFile = $fileValidator->clean($file['file']);
             try {
                 $uploadedFileRecord = tsUpload::create($validatedFile, $this->getOption('rule'))->process();
             } catch (tsUploadException $e) {
                 throw new sfValidatorError($this, $e->getMessage());
             }
             $uploadedFileRecord->name = $validatedFile->getOriginalName();
             $uploadedFileRecord->description = $validatedDescription;
             $uploads[] = $uploadedFileRecord;
         } elseif (isset($file['id'])) {
             $uploadedFileRecord = Doctrine::getTable($this->getOption('model'))->findOneById($file['id']);
             if ($uploadedFileRecord) {
                 $uploadedFileRecord->description = $validatedDescription;
                 $uploads[] = $uploadedFileRecord;
             }
         }
         if ($this->getOption('max_count') && count($uploads) > $this->getOption('max_count')) {
             throw new sfValidatorError($this, 'max_count', array('value' => $value, 'max_count' => $this->getOption('max_count')));
         }
     }
     return $uploads;
 }
 public function postValidator($validator, $values)
 {
     if (isset($values['categories_list_add']) && is_array($values['categories_list_add'])) {
         $stringValidator = new sfValidatorString();
         foreach ($values['categories_list_add'] as $key => $value) {
             $values['categories_list_add'][$key] = $stringValidator->clean($value);
         }
     }
     return $values;
 }
 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'] . '".');
         }
     }
 }
Ejemplo n.º 4
0
 public static function ValidateSearchRequest($request, $check_dates = false)
 {
     $date_from = $request->getParameter('date_from');
     $date_to = $request->getParameter('date_to');
     $city_name = $request->getParameter('city');
     $features = $request->getParameter('features');
     $errors = array();
     //  City______________
     $city = Doctrine_Core::getTable('City')->FindByNameLike($city_name);
     if (is_object($city) === false) {
         $error = 'City ' . $request->getParameter('city') . ' not found ... ';
         array_push($errors, $error);
     }
     $city_validator = new sfValidatorString(array('required' => true), array('required' => 'Please enter City to search'));
     try {
         $city_name = $city_validator->clean($city_name);
     } catch (sfValidatorError $e) {
         array_push($errors, $e);
     }
     //  Dates______________
     if ($check_dates) {
         if (strlen($date_from) > 1 === false) {
             array_push($errors, "Please enter date from.");
         }
         if (strlen($date_to) > 1 === false) {
             array_push($errors, "Please enter date to.");
         }
         if (strtotime($date_from) >= strtotime($date_to)) {
             array_push($errors, "Bad date range.");
         }
         if (LinkParser::CheckDate($date_from, '-', true) === false) {
             array_push($errors, "Invalid format for date from.");
         }
         if (LinkParser::CheckDate($date_to, '-', true) === false) {
             array_push($errors, "Invalid format for date to.");
         }
     }
     return $errors;
 }
Ejemplo n.º 5
0
<?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 __DIR__ . '/../../bootstrap/unit.php';
$t = new lime_test(12);
$v = new sfValidatorString();
// ->clean()
$t->diag('->clean()');
$t->is($v->clean('foo'), 'foo', '->clean() returns the string unmodified');
$v->setOption('required', false);
$t->ok($v->clean(null) === '', '->clean() converts the value to a string');
$t->ok($v->clean(1) === '1', '->clean() converts the value to a string');
$v->setOption('max_length', 2);
$t->is($v->clean('fo'), 'fo', '->clean() checks the maximum length allowed');
try {
    $v->clean('foo');
    $t->fail('"max_length" option set the maximum length of the string');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('"max_length" option set the maximum length of the string');
    $t->is($e->getCode(), 'max_length', '->clean() throws a sfValidatorError');
}
$v->setMessage('max_length', 'Too long');
try {
    $v->clean('foo');
 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;
     }
 }