Browse Source

Update previous commit

Visman 2 years ago
parent
commit
af44c5d6d8
2 changed files with 16 additions and 13 deletions
  1. 14 3
      app/Models/Pages/Auth.php
  2. 2 10
      app/Models/Pages/Register.php

+ 14 - 3
app/Models/Pages/Auth.php

@@ -243,7 +243,7 @@ class Auth extends Page
     /**
      * Запрос на смену кодовой фразы
      */
-    public function forget(array $args, string $method, string $email = ''): Page
+    public function forget(array $args, string $method, string $email = '', User $user = null): Page
     {
         $this->c->Lang->load('validator');
         $this->c->Lang->load('auth');
@@ -251,6 +251,17 @@ class Auth extends Page
         $v = null;
 
         if ('POST' === $method) {
+            // форма заполнена с помощью модели User
+            if (null !== $user) {
+                $postData = [
+                    'token'  => $this->c->Csrf->create('Forget'),
+                    'email'  => $user->email,
+                    'submit' => 'From User model',
+                ];
+            } else {
+                $postData = null;
+            }
+
             $v = $this->c->Validator->reset()
                 ->addValidators([
                 ])->addRules([
@@ -264,7 +275,7 @@ class Auth extends Page
                 ]);
 
             $v       = $this->c->Test->beforeValidation($v);
-            $isValid = $v->validation($_POST, true);
+            $isValid = $v->validation($postData ?? $_POST, true);
             $context = [
                 'user'    => $this->user->fLog(), // ???? Guest only?
                 'errors'  => $v->getErrorsWithoutType(),
@@ -284,7 +295,7 @@ class Auth extends Page
                     ]);
 
                 if (
-                    $v->validation($_POST)
+                    $v->validation($postData ?? $_POST)
                     && 0 === $this->c->bans->banFromName($tmpUser->username)
                 ) {
                     $this->c->Csrf->setHashExpiration(259200); // ???? хэш действует 72 часа

+ 2 - 10
app/Models/Pages/Register.php

@@ -476,18 +476,10 @@ class Register extends Page
             && 1 === $this->c->config->b_regs_verify
         ) {
             $isSent = true;
-            $flood  = \time() - $userInDB->last_email_sent;
 
             // отправка письма на сброс кодовой фразы
-            // костыль
-            if ($flood >= $this->c->FLOOD_INTERVAL) {
-                $_POST = [
-                    'token'  => $this->c->Csrf->create('Forget'),
-                    'email'  => $email,
-                    'submit' => 'From dupe registration',
-                ];
-
-                $this->c->Auth->forget([], 'POST');
+            if (\time() - $userInDB->last_email_sent >= $this->c->FLOOD_INTERVAL) {
+                $this->c->Auth->forget([], 'POST', '', $userInDB);
             }
 
             // письмо активации аккаунта отправлено