Visman 8 gadi atpakaļ
vecāks
revīzija
841694800d

+ 5 - 1
app/Controllers/Routing.php

@@ -50,6 +50,10 @@ class Routing
         } else {
         } else {
             // выход
             // выход
             $r->add('GET', '/logout/{token}', 'Auth:logout', 'Logout');
             $r->add('GET', '/logout/{token}', 'Auth:logout', 'Logout');
+
+            // обработка "кривых" перенаправлений с логина и регистрации
+            $r->add('GET', '/login[/{tail:.*}]', 'Redirect:toIndex');
+            $r->add('GET', '/registration[/{tail:.*}]', 'Redirect:toIndex');
         }
         }
         // просмотр разрешен
         // просмотр разрешен
         if ($user->gReadBoard == '1') {
         if ($user->gReadBoard == '1') {
@@ -106,7 +110,7 @@ class Routing
                 if ($user->gReadBoard != '1' && $user->isGuest) {
                 if ($user->gReadBoard != '1' && $user->isGuest) {
                     $page = $this->c->Redirect->setPage('Login');
                     $page = $this->c->Redirect->setPage('Login');
                 } else {
                 } else {
-//                  $page = $this->c->Message->message('Bad request');
+                    $page = $this->c->Message->message('Bad request');
                 }
                 }
                 break;
                 break;
             case $r::METHOD_NOT_ALLOWED:
             case $r::METHOD_NOT_ALLOWED:

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

@@ -29,19 +29,16 @@ class Auth extends Page
      */
      */
     public function logout($args)
     public function logout($args)
     {
     {
-        $this->c->Lang->load('login');
-
-        if ($this->c->Csrf->verify($args['token'], 'Logout', $args)) {
-            $user = $this->c->user;
-
-            $this->c->UserCookie->deleteUserCookie();
-            $this->c->Online->delete($user);
-            $this->c->UserMapper->updateLastVisit($user);
-
-            return $this->c->Redirect->setPage('Index')->setMessage(__('Logout redirect'));
+        if (! $this->c->Csrf->verify($args['token'], 'Logout', $args)) {
+            return $this->c->Redirect->setPage('Index')->setMessage(__('Bad token'));
         }
         }
 
 
-        return $this->c->Redirect->setPage('Index')->setMessage(__('Bad token'));
+        $this->c->UserCookie->deleteUserCookie();
+        $this->c->Online->delete($this->c->user);
+        $this->c->UserMapper->updateLastVisit($this->c->user);
+
+        $this->c->Lang->load('login');
+        return $this->c->Redirect->setPage('Index')->setMessage(__('Logout redirect'));
     }
     }
 
 
     /**
     /**
@@ -183,8 +180,8 @@ class Auth extends Page
     {
     {
         $this->c->Lang->load('login');
         $this->c->Lang->load('login');
 
 
-        $this->nameTpl = 'login/forget';
-        $this->onlinePos = 'forget';
+        $this->nameTpl = 'password_reset';
+        $this->onlinePos = 'password_reset';
 
 
         if (! isset($args['_email'])) {
         if (! isset($args['_email'])) {
             $args['_email'] = '';
             $args['_email'] = '';
@@ -246,7 +243,7 @@ class Auth extends Page
         $link = $this->c->Router->link('ChangePassword', ['email' => $data['email'], 'key' => $key, 'hash' => $hash]);
         $link = $this->c->Router->link('ChangePassword', ['email' => $data['email'], 'key' => $key, 'hash' => $hash]);
         $tplData = ['link' => $link];
         $tplData = ['link' => $link];
 
 
-        if ($mail->send($data['email'], 'change_password.tpl', $tplData)) {
+        if ($mail->send($data['email'], 'password_reset.tpl', $tplData)) {
             $this->c->UserMapper->updateUser($user->id, ['activate_string' => $key, 'last_email_sent' => time()]);
             $this->c->UserMapper->updateUser($user->id, ['activate_string' => $key, 'last_email_sent' => time()]);
             return $this->c->Message->message(__('Forget mail', $this->config['o_admin_email']), false, 200);
             return $this->c->Message->message(__('Forget mail', $this->config['o_admin_email']), false, 200);
         } else {
         } else {
@@ -261,8 +258,8 @@ class Auth extends Page
      */
      */
     public function changePass(array $args)
     public function changePass(array $args)
     {
     {
-        $this->nameTpl = 'login/password';
-        $this->onlinePos = 'password';
+        $this->nameTpl = 'change_password';
+        $this->onlinePos = 'change_password';
 
 
         if (isset($args['_ok'])) {
         if (isset($args['_ok'])) {
             unset($args['_ok']);
             unset($args['_ok']);
@@ -300,8 +297,6 @@ class Auth extends Page
      */
      */
     public function changePassPost(array $args)
     public function changePassPost(array $args)
     {
     {
-        $this->c->Lang->load('login');
-
         // что-то пошло не так
         // что-то пошло не так
         if (! hash_equals($args['hash'], $this->c->Secury->hash($args['email'] . $args['key']))
         if (! hash_equals($args['hash'], $this->c->Secury->hash($args['email'] . $args['key']))
             || ! $this->c->Mail->valid($args['email'])
             || ! $this->c->Mail->valid($args['email'])
@@ -313,6 +308,7 @@ class Auth extends Page
             return $this->c->Message->message(__('Bad request'), false);
             return $this->c->Message->message(__('Bad request'), false);
         }
         }
 
 
+        $this->c->Lang->load('login');
         $this->c->Lang->load('profile');
         $this->c->Lang->load('profile');
 
 
         $v = $this->c->Validator;
         $v = $this->c->Validator;

+ 10 - 1
app/Models/Pages/Redirect.php

@@ -31,6 +31,15 @@ class Redirect extends Page
         return ! empty($this->link);
         return ! empty($this->link);
     }
     }
 
 
+    /**
+     * Перенаправление на главную страницу форума
+     * @return Page
+     */
+    public function toIndex()
+    {
+        return $this->setPage('Index')->setMessage(__('Redirecting to index'));
+    }
+
     /**
     /**
      * Задает адрес перехода
      * Задает адрес перехода
      * @param string $marker
      * @param string $marker
@@ -66,7 +75,7 @@ class Redirect extends Page
             return $this;
             return $this;
         }
         }
 
 
-        $this->nameTpl = 'redirect';
+        $this->nameTpl = 'layouts/redirect';
         $this->titles = [
         $this->titles = [
             __('Redirecting'),
             __('Redirecting'),
         ];
         ];

+ 24 - 22
app/Models/UserCookie.php

@@ -4,7 +4,6 @@ namespace ForkBB\Models;
 
 
 use ForkBB\Core\Cookie;
 use ForkBB\Core\Cookie;
 use ForkBB\Core\Secury;
 use ForkBB\Core\Secury;
-use ForkBB\Core\Container;
 
 
 class UserCookie extends Cookie
 class UserCookie extends Cookie
 {
 {
@@ -12,12 +11,6 @@ class UserCookie extends Cookie
     const KEY1 = 'key1';
     const KEY1 = 'key1';
     const KEY2 = 'key2';
     const KEY2 = 'key2';
 
 
-    /**
-     * Контейнер
-     * @var Container
-     */
-    protected $c;
-
     /**
     /**
      * Флаг указывающий на режим "запомнить меня"
      * Флаг указывающий на режим "запомнить меня"
      * @var bool
      * @var bool
@@ -42,15 +35,30 @@ class UserCookie extends Cookie
      */
      */
     protected $passHash;
     protected $passHash;
 
 
+    /**
+     * Время жизни куки без запоминания
+     * @var int
+     */
+    protected $min;
+
+    /**
+     * Время жизни куки с запоминанием
+     * @var int
+     */
+    protected $max;
+
     /**
     /**
      * Конструктор
      * Конструктор
-     *
-     * @param Container $container
+     * @param Secury $secury
+     * @param array $options
+     * @param int $min
+     * @param int $max
      */
      */
-    public function __construct(Secury $secury, array $options, Container $container)
+    public function __construct(Secury $secury, array $options, $min, $max)
     {
     {
         parent::__construct($secury, $options);
         parent::__construct($secury, $options);
-        $this->c = $container;
+        $this->min = (int) $min;
+        $this->max = (int) $max;
         $this->init();
         $this->init();
     }
     }
 
 
@@ -81,8 +89,7 @@ class UserCookie extends Cookie
     }
     }
 
 
     /**
     /**
-     * Возвращает id юзера из печеньки
-     *
+     * Возвращает id юзера из куки
      * @return int|false
      * @return int|false
      */
      */
     public function id()
     public function id()
@@ -92,10 +99,8 @@ class UserCookie extends Cookie
 
 
     /**
     /**
      * Проверка хэша пароля
      * Проверка хэша пароля
-     *
      * @param int $id
      * @param int $id
      * @param string $hash
      * @param string $hash
-     *
      * @return bool
      * @return bool
      */
      */
     public function verifyHash($id, $hash)
     public function verifyHash($id, $hash)
@@ -105,12 +110,10 @@ class UserCookie extends Cookie
     }
     }
 
 
     /**
     /**
-     * Установка печеньки аутентификации юзера
-     *
+     * Установка куки аутентификации юзера
      * @param int $id
      * @param int $id
      * @param string $hash
      * @param string $hash
      * @param bool $remember
      * @param bool $remember
-     *
      * @return bool
      * @return bool
      */
      */
     public function setUserCookie($id, $hash, $remember = null)
     public function setUserCookie($id, $hash, $remember = null)
@@ -125,11 +128,11 @@ class UserCookie extends Cookie
                 && $this->remember
                 && $this->remember
             )
             )
         ) {
         ) {
-            $expTime = time() + $this->c->TIME_REMEMBER;
+            $expTime = time() + $this->max;
             $expire = $expTime;
             $expire = $expTime;
             $pfx = '';
             $pfx = '';
         } else {
         } else {
-            $expTime = time() + $this->c->config['o_timeout_visit'];
+            $expTime = time() + $this->min;
             $expire = 0;
             $expire = 0;
             $pfx = '-';
             $pfx = '-';
         }
         }
@@ -140,8 +143,7 @@ class UserCookie extends Cookie
     }
     }
 
 
     /**
     /**
-     * Удаление печеньки аутентификации юзера
-     *
+     * Удаление куки аутентификации юзера
      * @return bool
      * @return bool
      */
      */
     public function deleteUserCookie()
     public function deleteUserCookie()

+ 2 - 2
app/bootstrap.php

@@ -4,7 +4,7 @@ namespace ForkBB;
 
 
 use ForkBB\Core\Container;
 use ForkBB\Core\Container;
 use ForkBB\Models\Pages\Page;
 use ForkBB\Models\Pages\Page;
-use Exception;
+use RuntimeException;
 
 
 if (! defined('PUN_ROOT'))
 if (! defined('PUN_ROOT'))
 	exit('The constant PUN_ROOT must be defined and point to a valid FluxBB installation root directory.');
 	exit('The constant PUN_ROOT must be defined and point to a valid FluxBB installation root directory.');
@@ -42,7 +42,7 @@ if (file_exists(__DIR__ . '/config/main.php')) {
 } elseif (file_exists(__DIR__ . '/config/install.php')) {
 } elseif (file_exists(__DIR__ . '/config/install.php')) {
     $container = new Container(include __DIR__ . '/config/install.php');
     $container = new Container(include __DIR__ . '/config/install.php');
 } else {
 } else {
-    throw new Exception('Application is not configured');
+    throw new RuntimeException('Application is not configured');
 }
 }
 
 
 define('PUN', 1);
 define('PUN', 1);

+ 3 - 6
app/lang/English/common.po

@@ -24,6 +24,9 @@ msgstr "."
 msgid "lang_thousands_sep"
 msgid "lang_thousands_sep"
 msgstr ","
 msgstr ","
 
 
+msgid "Redirecting to index"
+msgstr "Redirecting to Index page."
+
 msgid "Bad token"
 msgid "Bad token"
 msgstr "Bad token."
 msgstr "Bad token."
 
 
@@ -36,12 +39,6 @@ msgstr "You do not have permission to view these forums."
 msgid "No permission"
 msgid "No permission"
 msgstr "You do not have permission to access this page."
 msgstr "You do not have permission to access this page."
 
 
-msgid "Bad referrer"
-msgstr "Bad csrf_hash. You were referred to this page from an unauthorized source."
-
-msgid "Bad csrf hash"
-msgstr "Bad CSRF hash. You were referred to this page from an unauthorized source."
-
 msgid "No cookie"
 msgid "No cookie"
 msgstr "You appear to have logged in successfully, however a cookie has not been set. Please check your settings and if applicable, enable cookies for this website."
 msgstr "You appear to have logged in successfully, however a cookie has not been set. Please check your settings and if applicable, enable cookies for this website."
 
 

+ 0 - 1
app/lang/English/mail/index.html

@@ -1 +0,0 @@
-<html><head><title>.</title></head><body>.</body></html>

+ 0 - 0
app/lang/English/mail/change_password.tpl → app/lang/English/mail/password_reset.tpl


+ 3 - 6
app/lang/Russian/common.po

@@ -24,6 +24,9 @@ msgstr "."
 msgid "lang_thousands_sep"
 msgid "lang_thousands_sep"
 msgstr ","
 msgstr ","
 
 
+msgid "Redirecting to index"
+msgstr "Перенаправление на главную страницу форума."
+
 msgid "Bad request"
 msgid "Bad request"
 msgstr "Неверный запрос. Ссылка, по которой вы перешли, является неверной или просроченной."
 msgstr "Неверный запрос. Ссылка, по которой вы перешли, является неверной или просроченной."
 
 
@@ -36,12 +39,6 @@ msgstr "У вас нет прав на просмотр этой страниц
 msgid "Bad token"
 msgid "Bad token"
 msgstr "Неверный токен."
 msgstr "Неверный токен."
 
 
-msgid "Bad referrer"
-msgstr "Неверный csrf_hash. Вы перешли на эту страницу из неавторизованного источника."
-
-msgid "Bad csrf hash"
-msgstr "Неверный CSRF хэш. Вы перешли на эту страницу из неавторизованного источника."
-
 msgid "No cookie"
 msgid "No cookie"
 msgstr "Вы вошли, но куки (cookie) не были установлены. Пожалуйста проверьте настройки браузера и, если возможно, разрешите куки для этого сайта."
 msgstr "Вы вошли, но куки (cookie) не были установлены. Пожалуйста проверьте настройки браузера и, если возможно, разрешите куки для этого сайта."
 
 

+ 0 - 8
app/lang/Russian/mail/index.html

@@ -1,8 +0,0 @@
-<html>
-<head>
-<title>.</title>
-</head>
-<body>
-.
-</body>
-</html>

+ 0 - 0
app/lang/Russian/mail/change_password.tpl → app/lang/Russian/mail/password_reset.tpl


+ 0 - 0
app/templates/login/password.tpl → app/templates/change_password.tpl


+ 0 - 0
app/templates/redirect.tpl → app/templates/layouts/redirect.tpl


+ 0 - 0
app/templates/login/forget.tpl → app/templates/password_reset.tpl