From 09ad0f1ca17443deeed12fc4f3437a0ce2c1c3e3 Mon Sep 17 00:00:00 2001 From: RomanSteinberg <romanofficial@yandex.ru> Date: Mon, 18 May 2015 17:10:37 +0300 Subject: [PATCH] add maintenance page --- db/fix.sql | 3 ++ ~dev_rating/application/bootstrap.php | 18 +++++-- .../classes/Controller/Authentication.php | 50 +++++++++++++++++-- .../application/views/errors/http.twig | 2 +- .../account/classes/Model/Kohana/Account.php | 11 ++++ 5 files changed, 75 insertions(+), 9 deletions(-) diff --git a/db/fix.sql b/db/fix.sql index 462e6ca33..10434f98a 100644 --- a/db/fix.sql +++ b/db/fix.sql @@ -86,3 +86,6 @@ ALTER TABLE `students_groups` CHANGE IsStudyLeave `IsStudyLeave` tinyint(1) NOT ALTER TABLE `specializations` CHANGE Name `Name` varchar(200) CHARACTER SET utf8 NULL; +# 18.05.15 +SELECT SetSettings('maintenance_active', 1, NULL); +SELECT SetSettings('maintenance_return', NULL, "18.05.2015 17:00:00"); diff --git a/~dev_rating/application/bootstrap.php b/~dev_rating/application/bootstrap.php index 3553cbf3b..b7723ec05 100644 --- a/~dev_rating/application/bootstrap.php +++ b/~dev_rating/application/bootstrap.php @@ -145,12 +145,20 @@ Kohana::modules(array( * defaults for the URI. */ -/* --------------- Авторизация ---------------- */ +/* --------------- Авторизация ---------------- */ + Route::set('sign', '(sign(/<type>))', array('type' => '(up|in)')) - ->defaults(array( - 'controller' => 'authentication', - 'action' => 'sign', - )); + ->defaults(array( + 'controller' => 'authentication', + 'action' => 'enter_frontdoor', + )); + +Route::set('secret_entrance', '(ssign(/<type>))', array('type' => '(up|in)')) + ->defaults(array( + 'controller' => 'authentication', + 'action' => 'enter_backdoor', + )); + Route::set('remind', 'remind') ->defaults(array( diff --git a/~dev_rating/application/classes/Controller/Authentication.php b/~dev_rating/application/classes/Controller/Authentication.php index a1687a4cf..16551199f 100644 --- a/~dev_rating/application/classes/Controller/Authentication.php +++ b/~dev_rating/application/classes/Controller/Authentication.php @@ -29,8 +29,8 @@ class Controller_Authentication extends Controller { $updates['Text'] = $text; return $updates; } - - public function action_sign() + + private function sign() { if(!User::instance()->isSignedIn()) { @@ -42,7 +42,29 @@ class Controller_Authentication extends Controller { $this->response->body($twig); } } - + + public function action_enter_backdoor() + { + $this->sign(); + } + + public function action_enter_frontdoor() + { + $check = false; + $role = (int)User::instance()->offsetGet("RoleMark"); + $isNotSigned = !User::instance()->isSignedIn(); + + if($isNotSigned || ($role & 8) == 0) // if not signed or not admin + { + $check = $this->check_maintenance(); + User::instance()->signOut(); + } + + if (!$check) { + $this->sign(); + } + } + public function action_remind() { if(!User::instance()->isSignedIn()) @@ -76,4 +98,26 @@ class Controller_Authentication extends Controller { $this->redirect('sign', 302); } + private function check_maintenance() + { + $model = new Model_Account; + $maintenance_info = $model->getMaintenanceInfo(); + if ($maintenance_info['active']) { + $this->response->status(503); + $twig = Twig::factory('errors/http'); + $twig->title = 'Закрыто на техобслуживание!'; + $twig->code = 503; + $twig->message = "Восстановление работы сервиса: " . $maintenance_info['return']; + $this->response->body($twig); + return true; + } + else + return false; + } + + public function action_check_maintenance() + { + $this->check_maintenance(); + } + } // End Welcome diff --git a/~dev_rating/application/views/errors/http.twig b/~dev_rating/application/views/errors/http.twig index ebb2e1cab..b7dcdffa2 100644 --- a/~dev_rating/application/views/errors/http.twig +++ b/~dev_rating/application/views/errors/http.twig @@ -27,7 +27,7 @@ <div class="main_layer" style="width: 500px;"> <div class="main"> <div class="main_content sidePadding" style="overflow: hidden; text-align: center; padding: 10px"> - <h2 style="margin:0">Ошибочка вышла!</h2> + <h2 style="margin:0">{% if title != '' %} {{ title }} {% else %} Ошибка! {% endif %}</h2> <div style="font-size: 8em;">{{ code }}</div> <div style="color: #999; font-size: 1em;">{{ message }}</div> <div><a href="{{ link }}" style='font-size: 1em; color: #0183ce; text-decoration: none;'>Вернуться на главную страницу</a></div> diff --git a/~dev_rating/modules/account/classes/Model/Kohana/Account.php b/~dev_rating/modules/account/classes/Model/Kohana/Account.php index a7c768677..7d58dbaee 100644 --- a/~dev_rating/modules/account/classes/Model/Kohana/Account.php +++ b/~dev_rating/modules/account/classes/Model/Kohana/Account.php @@ -17,6 +17,17 @@ class Model_Kohana_Account extends Model return $key->get('ValS'); } + public function getMaintenanceInfo() + { + $sql = "CALL `GetSettings`('maintenance_active');"; + $key = DB::query(Database::SELECT, $sql)->execute(); + $result['active'] = ($key->get('Val') == 1); + $sql = "CALL `GetSettings`('maintenance_return');"; + $key = DB::query(Database::SELECT, $sql)->execute(); + $result['return'] = $key->get('ValS'); + return $result; + } + public function checkAuth($login, $password) { $db = Database::instance(); $login = $db->escape($login); -- GitLab