Skip to content
Snippets Groups Projects
Commit b2fe146f authored by PavelBegunkov's avatar PavelBegunkov
Browse files

php refactoring

parent c97df269
Branches
Tags
No related merge requests found
......@@ -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');
......
......@@ -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
}
......@@ -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);
......
......@@ -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);
}
......
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