diff --git a/db/fix.sql b/db/fix.sql index 462e6ca338056b64dfd6111f78af9b288267375d..10434f98accc6ff7621bfc449009235444eabc21 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 3553cbf3b97fd9191a1c741d3420e0000044361f..b7723ec058934e35a1e92d72e7ec2071bdd932ff 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 a1687a4cf8e446b777de266c308b716df5993d40..16551199ffd0a249ae0c9beda4ae910b15dfec60 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 ebb2e1cab01529de50262e2060866faca8f85456..b7dcdffa2ba4c7de7100a5b3a45665b90f35fce5 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 a7c768677ce2ab25b7bd4f8844acb1ddb7351e0f..7d58dbaee99e84d988b28952210f7398452eeec8 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);