Skip to content
Snippets Groups Projects
Commit 09ad0f1c authored by RomanSteinberg's avatar RomanSteinberg
Browse files

add maintenance page

parent 6a230200
Branches
Tags
No related merge requests found
......@@ -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");
......@@ -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(
......
......@@ -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
......@@ -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>
......
......@@ -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);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment