Add strict mode for validation
This commit is contained in:
parent
90c7a18a2e
commit
74c5b7d7a5
4 changed files with 18 additions and 9 deletions
|
@ -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;
|
||||
|
|
|
@ -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 = '';
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class Register extends Page
|
|||
|
||||
// завершение регистрации
|
||||
if (
|
||||
$v->validation($_POST)
|
||||
$v->validation($_POST, true)
|
||||
&& 1 === $v->on
|
||||
) {
|
||||
return $this->regEnd($v);
|
||||
|
|
Loading…
Add table
Reference in a new issue