diff --git a/~dev_rating/application/classes/Controller/Authentication.php b/~dev_rating/application/classes/Controller/Authentication.php index 54e5fcbe0df7555db31027968f4177d806e76528..1b9f8fbf3a61c95fc7602b39def0416a2c1a7572 100644 --- a/~dev_rating/application/classes/Controller/Authentication.php +++ b/~dev_rating/application/classes/Controller/Authentication.php @@ -4,30 +4,30 @@ class Controller_Authentication extends Controller { public function before() { parent::before(); - if(UTF8::strcasecmp($this->request->action(), 'logout')) - { - if(User::instance()->isSignedIn()) - { - $page = Request::factory(User::instance()->offsetGet('Type').'/index')->execute(); + if(UTF8::strcasecmp($this->request->action(), 'logout')) { + $user = User::instance(); + if($user->isSignedIn()) { + $request = $user->offsetGet('Type').'/index'; + $page = Request::factory($request)->execute(); $this->response->body($page); } } } - protected function getUpdates() { + protected function getUpdates() + { $fp = fopen(APPPATH.'updates.txt', 'r'); - $updates['Date'] = fgets($fp, 999); - $updates['Text'] = '<ol>'; - if ($fp) - { - while (!feof($fp)) - { - $updates['Text'] = $updates['Text'].'<li>'.fgets($fp, 999).'</li>'; - } + $updates['Date'] = fgets($fp, 999); + $text = '<ol>'; + if ($fp) { + while (!feof($fp)) { + $text .= '<li>'.fgets($fp, 999).'</li>'; } - $updates['Text'] = $updates['Text'].'</ol>'; - return $updates; + } + $text .= '</ol>'; + $updates['Text'] = $text; + return $updates; } public function action_sign() @@ -48,7 +48,7 @@ class Controller_Authentication extends Controller { if(!User::instance()->isSignedIn()) { $twig = Twig::factory('sign/remindpass'); - $twig->Updates = $twig->Updates = self::getUpdates(); + $twig->Updates = self::getUpdates(); $this->response->body($twig); } } @@ -56,9 +56,10 @@ class Controller_Authentication extends Controller { public function action_endremind() { $token = $this->request->param('token'); - if(!Account::instance()->checkToken($token)) - throw HTTP_Exception::factory (403, - 'Сожалеем, но данная ссылка для восстановления пароля более недействительна!'); + if (!Account::instance()->checkToken($token)) { + throw HTTP_Exception::factory(403, + 'Сожалеем, но данная ссылка для восстановления пароля более недействительна!'); + } if(!User::instance()->isSignedIn()) { $twig = Twig::factory('sign/changepass'); diff --git a/~dev_rating/application/classes/Controller/Handler.php b/~dev_rating/application/classes/Controller/Handler.php index 2a03b36ee911714cdd19ab3c9b30743b5e971d77..6e6b1d0d9150edae23762c09f2b96ce27b4555df 100644 --- a/~dev_rating/application/classes/Controller/Handler.php +++ b/~dev_rating/application/classes/Controller/Handler.php @@ -11,6 +11,7 @@ class Controller_Handler extends Controller { public function before() { $isDownload = Cookie::get('fD'); + $user = User::instance(); // Если у нас запрос идет не из AJAX if(!$this->request->is_ajax() && !$isDownload) { @@ -23,16 +24,18 @@ class Controller_Handler extends Controller { $this->get = Validation::factory(Arr::map('trim', $_GET)); // Если авторизован, получаем данные аккаунта - if(User::instance()->isSignedIn()) + if($user->isSignedIn()) { - $this->user = User::instance()->getInfoAsArray(); + $this->user = $user->getInfoAsArray(); } // Получаем имя маршрута - $route = Route::name($this->request->route()).':'.$this->request->controller(); - $userMark = User::instance()->offsetGet('RoleMark'); + $route = Route::name($this->request->route()); + $route .= ':'.$this->request->controller(); + $userMark = $user->offsetGet('RoleMark'); // Если запрос не прошел на проверку доступа - if(!$this->checkAccessLevel() || !$this->checkBitmask($userMark, $route)) + if( !$this->checkAccessLevel() || + !$this->checkBitmask($userMark, $route)) { // Перенаправляем на ошибку доступа throw HTTP_Exception::factory (403); @@ -70,4 +73,4 @@ class Controller_Handler extends Controller { break; } } -} \ No newline at end of file +} diff --git a/~dev_rating/application/classes/Controller/Twig.php b/~dev_rating/application/classes/Controller/Twig.php index d1f2614b755e2753c6f324a50c5abdaa29165ac0..231cc71368275e961d96b9c19b6fd6ff3318af2a 100644 --- a/~dev_rating/application/classes/Controller/Twig.php +++ b/~dev_rating/application/classes/Controller/Twig.php @@ -4,8 +4,8 @@ class Controller_Twig extends Controller { public function action_show() { - $path = $this->request->param('id'); - $path = UTF8::str_ireplace(':', '/', $path); + $id = $this->request->param('id'); + $path = UTF8::str_ireplace(':', '/', $id); if(Kohana::find_file('views', $path, 'twig')) { $twig = Twig::factory($path); diff --git a/~dev_rating/application/classes/Controller/UserEnvi.php b/~dev_rating/application/classes/Controller/UserEnvi.php index 095f2601a2b1ffb29b87ef7c19bf8937cee79e46..c0c1369132d493540ee9e7fee16af0fe4b0712d7 100644 --- a/~dev_rating/application/classes/Controller/UserEnvi.php +++ b/~dev_rating/application/classes/Controller/UserEnvi.php @@ -2,54 +2,48 @@ class Controller_UserEnvi extends Controller { protected $UserInfo; + protected static $degrees = array( 'bachelor' => 'Бакалавриат', + 'specialist' => 'Специалитет', + 'master' => 'Магистратура'); + public function before() { - if(!User::instance()->isSignedIn()) - { + $user = User::instance(); + if(!$user->isSignedIn()) { $this->redirect('sign', 302); + return; + } + $this->UserInfo = $user->getInfoAsArray(); + if($this->UserInfo['Type'] == 'student') { + //unified degree from db + $uniDegree = $this->UserInfo['Degree']; + $this->UserInfo['Degree'] = $this->degrees[$uniDegree]; } - else - { - - // Проверка на - $this->UserInfo = User::instance()->getInfoAsArray(); - if($this->UserInfo['Type'] == 'student') - { - $degrees = array('bachelor' => 'Бакалавриат', 'specialist' => 'Специалитет', 'master' => 'Магистратура'); - $this->UserInfo['Degree'] = $degrees[$this->UserInfo['Degree']]; - } - // Проверка на доступ к странице - $route = Route::name($this->request->route()); - $userMark = User::instance()->offsetGet('RoleMark'); - $sysModel = new Model_System; - $bitmask = $sysModel->getBitmaskForRoute($route); - if(!($bitmask & $userMark)) - { - throw HTTP_Exception::factory(403, 'Не пытайтесь попасть туда, куда попадать не следует.'); - } + // Проверка на доступ к странице + $route = Route::name($this->request->route()); + $userMark = $user->offsetGet('RoleMark'); + $sysModel = new Model_System; + $bitmask = $sysModel->getBitmaskForRoute($route); + if(!($bitmask & $userMark)) { + throw HTTP_Exception::factory(403, + 'Не пытайтесь попасть туда, куда попадать не следует.'); } } public function action_index() { - $page = Request::factory($this->UserInfo['Type'].'/index')->execute(); + $type = $this->UserInfo['Type']; + $page = Request::factory($type.'/index')->execute(); $this->response->body($page); } public function action_profile() { - if($this->UserInfo['Type'] != 'teacher') - { + if($this->UserInfo['Type'] != 'teacher') { $this->redirect('/', 302); - } - else - { + } else { $url = "teacher/profile"; - if(!empty($type)) - $url .= '/'.$type; - if(!empty($id)) - $url .= '/'.$id; $page = Request::factory($url)->execute(); $this->response->body($page); }