Add strict mode for validation

This commit is contained in:
Visman 2020-10-10 11:15:07 +07:00
parent 90c7a18a2e
commit 74c5b7d7a5
4 changed files with 18 additions and 9 deletions

View file

@ -234,7 +234,7 @@ class Validator
/**
* Проверяет данные
*/
public function validation(array $raw): bool
public function validation(array $raw, bool $strict = false): bool
{
if (empty($this->rules)) {
throw new RuntimeException('Rules not found');
@ -249,7 +249,15 @@ class Validator
$this->__get($field);
}
$this->raw = null;
if (
$strict
&& empty($this->errors)
&& ! empty(\array_diff_key($this->raw, $this->fields))
) {
$this->addError('Too much data');
}
$this->raw = null;
return empty($this->errors);
}
@ -848,7 +856,7 @@ class Validator
return $value;
}
public function vDate(Validator $v, $value)
protected function vDate(Validator $v, $value)
{
if ($this->noValue($value)) {
return null;

View file

@ -53,7 +53,7 @@ class Auth extends Page
'password' => 'Passphrase',
]);
if ($v->validation($_POST)) {
if ($v->validation($_POST, true)) {
return $this->c->Redirect->url($v->redirect)->message('Login redirect');
}
@ -186,7 +186,7 @@ class Auth extends Page
'email.email' => $tmpUser, // сюда идет возрат данных по найденному пользователю
]);
if ($v->validation($_POST)) {
if ($v->validation($_POST, true)) {
$key = $this->c->Secury->randomPass(32);
$hash = $this->c->Secury->hash($tmpUser->id . $key);
$link = $this->c->Router->link(
@ -317,7 +317,7 @@ class Auth extends Page
'password2.same' => 'Pass not match',
]);
if ($v->validation($_POST)) {
if ($v->validation($_POST, true)) {
$user->password = \password_hash($v->password, \PASSWORD_DEFAULT);
$user->email_confirmed = 1;
$user->activate_string = '';

View file

@ -36,7 +36,7 @@ class Post extends Page
$v = $this->messageValidator($forum, 'NewTopic', $args, false, true);
if (
$v->validation($_POST)
$v->validation($_POST, $this->user->isGuest) //????
&& null === $v->preview
&& null !== $v->submit
) {
@ -94,8 +94,9 @@ class Post extends Page
$v = $this->messageValidator($topic, 'NewReply', $args);
if (
$v->validation($_POST)
$v->validation($_POST, $this->user->isGuest) //????
&& null === $v->preview
&& null !== $v->submit
) {
return $this->endPost($topic, $v);
}

View file

@ -41,7 +41,7 @@ class Register extends Page
// завершение регистрации
if (
$v->validation($_POST)
$v->validation($_POST, true)
&& 1 === $v->on
) {
return $this->regEnd($v);