Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Added validator field name array support, changed checkout validator rules

givanz4d896faa1612
diff --git a/app/validate/card.php b/app/validate/card.php
new file mode 100644
index 0000000..c2bbd35
--- /dev/null
+++ b/app/validate/card.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+return [
+ 'card.number' => [
+ 'notEmpty' => '',
+ 'maxLength' => 19,
+ ],
+ 'card.expiryMonth' => [
+ 'notEmpty' => '',
+ 'maxLength' => 2,
+ ],
+ 'card.expiryYear' => [
+ 'notEmpty' => '',
+ 'maxLength' => 2,
+ ],
+ 'card.cvv' => [
+ 'notEmpty' => '',
+ 'maxLength' => 4,
+ ],
+];
diff --git a/app/validate/checkout_billing.php b/app/validate/checkout_billing.php
index 0a5a68b..19f7dca 100755
--- a/app/validate/checkout_billing.php
+++ b/app/validate/checkout_billing.php
@@ -23,14 +23,14 @@
use function Vvveb\__;
return [
- 'billing_first_name' => [
+ 'billing_address.first_name' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],
- 'billing_last_name' => [
+ 'billing_address.last_name' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
@@ -38,51 +38,51 @@ return [
'message' => __('%s must not be greater than 100'), ],
],
/*
- 'billing_company' => [
+ 'billing_address.company' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],*/
- 'billing_address_1' => [
+ 'billing_address.address_1' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],
- 'billing_address_2' => [
+ 'billing_address.address_2' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],
- 'billing_city' => [
+ 'billing_address.city' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],
- 'billing_post_code' => [
+ 'billing_address.post_code' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],
- 'billing_country_id' => [
+ 'billing_address.country_id' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
],
- 'billing_region_id' => [
+ 'billing_address.region_id' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
],
/*
- 'billing_phone_number' => [
+ 'billing_address.phone_number' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
],*/
diff --git a/app/validate/checkout_shipping.php b/app/validate/checkout_shipping.php
index 192349f..3cc0072 100755
--- a/app/validate/checkout_shipping.php
+++ b/app/validate/checkout_shipping.php
@@ -23,60 +23,60 @@
use function Vvveb\__;
return [
- 'shipping_first_name' => [
+ 'shipping_address.first_name' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],
- 'shipping_last_name' => [
+ 'shipping_address.last_name' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
], /*
- 'shipping_company' => [
+ 'shipping_address.company' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],*/
- 'shipping_address_1' => [
+ 'shipping_address.address_1' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],
- 'shipping_address_2' => [
+ 'shipping_address.address_2' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],
- 'shipping_city' => [
+ 'shipping_address.city' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],
- 'shipping_post_code' => [
+ 'shipping_address.post_code' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
['maxLength' => 100,
'message' => __('%s must not be greater than 100'), ],
],
- 'shipping_country_id' => [
+ 'shipping_address.country_id' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
],
- 'shipping_region_id' => [
+ 'shipping_address.region_id' => [
['notEmpty' => '',
'message' => '%s must not be empty', ],
],
diff --git a/system/validator.php b/system/validator.php
index 6acac72..2f7d673 100755
--- a/system/validator.php
+++ b/system/validator.php
@@ -47,6 +47,7 @@ class Validator {
'captcha' => __('%s is invalid'),
'session' => __('%s is invalid'),
'email' => __('%s invalid email'),
+ 'integer' => __('%s not numeric'),
'passwordComplexity' => __('%s not complex enough, include uppercase letters and digits'),
];
@@ -70,13 +71,32 @@ class Validator {
$this->rules = $rules;
}
+ //remove rule
+ function removeRule($rule) {
+ unset($this->rules[$rule]);
+ }
+
//remove keys that are not in the validation list
function filter($input) {
$validKeys = array_keys($this->rules);
+ $filter = [];
+
+ foreach ($validKeys as $key) {
+ if (strpos($key, '.') != false) {
+ $keys = explode('.', $key);
+ $filter[$keys[0]][$keys[1]] = arrayPath($input, $key);
+ } else {
+ if (isset($input[$key])) {
+ $filter[$key] = $input[$key];
+ }
+ }
+ }
+ return $filter;
+ /*
return array_filter($input, function ($key) use ($validKeys) {
- return in_array($key,$validKeys);
- }, ARRAY_FILTER_USE_KEY);
+ return in_array($key, $validKeys);
+ }, ARRAY_FILTER_USE_KEY);*/
}
function validate($input) {
@@ -234,6 +254,14 @@ class Validator {
return false;
}
+ function ruleNumeric($value, $options, $name, $message, $input) {
+ if (! is_numeric($value)) {
+ return sprintf(__($message), $name, $options);
+ }
+
+ return false;
+ }
+
function rulePasswordComplexity($value, $options, $name, $message, $input) {
switch ($options) {
case 'low':