Esempio n. 1
0
 function validate()
 {
     $validator = new Validator($this->_value);
     if ($this->isRequired()) {
         $validator->required(sprintf("%s cannot be blank", $this->getName()));
     }
     $this->_errors = $validator->allErrors();
     return $this->allErrors();
 }
Esempio n. 2
0
 /**
  * @return boolean Returns true when successful.
  */
 private static function text($connection, $type, $function, $line, $text = '')
 {
     // Check dependencies
     Validator::required(isset($connection, $type, $function, $line, $text), __METHOD__);
     // Get time
     $sysstamp = time();
     // Save in database
     $query = Database::prepare($connection, "INSERT INTO ? (time, type, function, line, text) VALUES ('?', '?', '?', '?', '?')", array(LYCHEE_TABLE_LOG, $sysstamp, $type, $function, $line, $text));
     $result = Database::execute($connection, $query, null, null);
     if ($result === false) {
         return false;
     }
     return true;
 }
Esempio n. 3
0
function ValidateInput()
{
    if ($_SERVER['CONTENT_LENGTH'] > getPhpConfBytes()) {
        FormPage::GetInstance()->SetErrors(array(array('field' => 'Form', 'err' => _T('The form is attempting to send more data than the server allows. Please check that you are not uploading too many large files.'))));
        return 1;
    }
    $cfg = Config::GetInstance()->GetConfig('rules');
    if ($cfg === false) {
        return 1;
    }
    $validator = new Validator();
    $conditionals = new Conditionals();
    foreach ($cfg as $name => $rules) {
        // skip all rules that have a name with a _ prefix
        if ($name[0] == '_') {
            continue;
        }
        if ($conditionals->IsFieldIgnored($name)) {
            continue;
        }
        $fieldtype = $rules->fieldtype;
        if (method_exists('Validator', $fieldtype)) {
            if (!$validator->required($name, $rules)) {
                continue;
            } else {
                $validator->{$fieldtype}($name, $rules);
            }
        } else {
            writeErrorLog('Validation handler missing for fieldtype: ', $fieldtype);
        }
    }
    $errcount = count($validator->errors);
    // ready, assign the result to the page instance
    if ($errcount > 0) {
        FormPage::GetInstance()->SetErrors($validator->errors);
    } else {
        FormPage::GetInstance()->SetPostValues($validator->post);
    }
    return $errcount;
}
Esempio n. 4
0
 public function subscribeNewsletter()
 {
     $validator = new Validator();
     $req = array('subscriber_email' => t("Email is required"));
     $req_email = array('subscriber_email' => t("Email address seems invalid"));
     $validator->required($req, $this->data);
     $validator->email($req_email, $this->data);
     if (Yii::app()->functions->getSubsriberEmail($this->data['subscriber_email'])) {
         $validator->msg[] = t("Sorry your Email address is already exist in our records.");
     }
     if ($validator->validate()) {
         $params = array('email_address' => $this->data['subscriber_email'], 'date_created' => date('c'), 'ip_address' => $_SERVER['REMOTE_ADDR']);
         if ($this->insertData("{{newsletter}}", $params)) {
             $this->code = 1;
             $this->msg = t("Thank you for subscribing to our mailing list!");
         } else {
             $this->msg = t("Sorry there is error while we saving your information.");
         }
     } else {
         $this->msg = $validator->getErrorAsHTML();
     }
 }
Esempio n. 5
0
 /**
  * Sets a new username.
  * @return boolean Returns true when successful.
  */
 private static function setPassword($password)
 {
     // Check dependencies
     Validator::required(isset($password), __METHOD__);
     // Hash password
     $password = getHashedString($password);
     // Do not prepare $password because it is hashed and save
     // Preparing (escaping) the password would destroy the hash
     if (self::set('password', $password, true) === false) {
         return false;
     }
     return true;
 }
Esempio n. 6
0
         $retHashSeq = $merchant_salt . '|' . $status . '|||||||||||' . $email . '|' . $firstname . '|' . $productinfo . '|' . $amount . '|' . $txnid . '|' . $key;
     }
     $hash = hash("sha512", $retHashSeq);
     if ($hash == $posted_hash) {
         if ($status == "success") {
             $success = true;
         } else {
             $error1 = Yii::t("default", "Transaction failed." . " " . $status);
         }
     } else {
         $error1 = Yii::t("default", "Invalid Transaction. Please try again");
     }
 } else {
     $Validator = new Validator();
     $req = array('firstname' => Yii::t("default", "First name is required"), 'email' => Yii::t("default", "Email address is required"), 'phone' => Yii::t("default", "Phone is required"));
     $Validator->required($req, $data_post);
     if ($Validator->validate()) {
         //$amount_to_pay=number_format($amount_to_pay,0);
         $amount_to_pay = normalPrettyPrice($amount_to_pay);
         $hash_string = "{$merchant_key}|{$payment_ref}|{$amount_to_pay}|{$payment_description}|";
         $hash_string .= $data_post['firstname'] . "|";
         $hash_string .= $data_post['email'] . "|||||||||||";
         $hash_string .= $merchant_salt;
         $merchant_hash = strtolower(hash('sha512', $hash_string));
         $action = $PAYU_BASE_URL . '/_payment';
         /*dump($hash_string);
           dump($action);
           die();*/
     } else {
         $error1 = $Validator->getErrorAsHTML();
     }
Esempio n. 7
0
 public function validateColumns($datarow)
 {
     if (!is_a($datarow, 'ModelDataRow')) {
         throw new InvalidModelException('Argument type mismatch (ModelDataRow expected, ' . gettype($datarow) . ' found)');
     }
     $error = array();
     foreach ($this->getSchema()['columns'] as $column => $columnSchema) {
         $value = $datarow->{$column};
         $isRequired = FALSE;
         /*
          * Check if the field is required, i.e. must be filled
          */
         if (isset($columnSchema['rule'])) {
             if (in_array('required', $columnSchema['rule'])) {
                 $isRequired = TRUE;
                 if (!Validator::required($value)) {
                     $this->lastError[$column][] = 'required';
                     continue;
                 }
             }
         }
         if (!$isRequired) {
             /*
              * If the column is not a required field, only performs 
              * checking when the field is non-empty
              */
             if (!Validator::nonEmpty($value)) {
                 continue;
             }
         }
         /*
          * Perform type checking
          */
         if ($columnSchema['type'] == 'array') {
             if (!Validator::arraytype($value)) {
                 $error[$column][] = 'array';
             }
             $datarow->{$column} = json_encode($datarow->{$column});
         } elseif ($columnSchema['type'] == 'object') {
             if (!Validator::object($value)) {
                 $error[$column][] = 'object';
             }
             $datarow->{$column} = json_encode($datarow->{$column});
         } elseif ($columnSchema['type'] == 'universial') {
             // no type checking needed
         } else {
             if (!call_user_func(array('Validator', $columnSchema['type']), $value)) {
                 $error[$column][] = $columnSchema['type'];
             }
         }
         /*
          * Perform rule checking
          */
         if (isset($columnSchema['rule'])) {
             foreach ($columnSchema['rule'] as $rule) {
                 if (is_array($rule)) {
                     if (method_exists('Validator', $rule[0])) {
                         $parameters = array_slice($rule, 1);
                         array_unshift($parameters, $value);
                         if (!call_user_func_array(array('Validator', $rule[0]), $parameters)) {
                             $error[$column][] = $rule[0];
                         }
                     }
                 } else {
                     /*
                      * Special case, the rule is unique
                      */
                     if ($rule == 'unique') {
                         if ($datarow->id == NULL) {
                             if (!$this->unique($column, $value)) {
                                 $error[$column][] = 'unique';
                             }
                         } else {
                             if (!$this->unique($column, $value, $datarow->id)) {
                                 $error[$column][] = 'unique';
                             }
                         }
                     } else {
                         if (method_exists('Validator', $rule)) {
                             if (!call_user_func(array('Validator', $rule), $value)) {
                                 $error[$column][] = $rule;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (count($error) > 0) {
         $this->lastError = $error;
         return FALSE;
     }
     return TRUE;
 }
Esempio n. 8
0
 public function addDish()
 {
     $Validator = new Validator();
     $req = array('dish_name' => Yii::t("default", "Dish name is required"), 'spicydish' => t("Icon is required"));
     $Validator->required($req, $this->data);
     if ($Validator->validate()) {
         $params = array('dish_name' => $this->data['dish_name'], 'photo' => $this->data['spicydish'], 'status' => $this->data['status'], 'date_created' => date('c'), 'ip_address' => $_SERVER['REMOTE_ADDR']);
         if (empty($this->data['id'])) {
             if ($this->insertData("{{dishes}}", $params)) {
                 $this->details = Yii::app()->db->getLastInsertID();
                 $this->code = 1;
                 $this->msg = Yii::t("default", "Successful");
             }
         } else {
             unset($params['date_created']);
             $params['date_modified'] = date('c');
             $res = $this->updateData('{{dishes}}', $params, 'dish_id', $this->data['id']);
             if ($res) {
                 $this->code = 1;
                 $this->msg = Yii::t("default", 'Dish updated');
             } else {
                 $this->msg = Yii::t("default", "ERROR: cannot update");
             }
         }
     } else {
         $this->msg = $Validator->getErrorAsHTML();
     }
 }