From 5e199a6696424f86548684f27c61800af62b2db4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=A0=D1=83=D0=B4?=
 =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D1=86?= <andrey.rudenets@gmail.com>
Date: Fri, 22 Aug 2014 23:06:39 +0400
Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?=
 =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=B3=D0=BE=D0=B2,=20vo?=
 =?UTF-8?q?l.2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 db/StoredProcedures.sql                              |  3 ++-
 ~dev_rating/application/bootstrap.php                |  6 +++---
 .../application/classes/Controller/UserEnvi.php      | 12 ++++++------
 ~dev_rating/application/classes/Model/System.php     | 10 ++++++++++
 ~dev_rating/modules/account/classes/Kohana/User.php  |  4 +---
 5 files changed, 22 insertions(+), 13 deletions(-)
 create mode 100644 ~dev_rating/application/classes/Model/System.php

diff --git a/db/StoredProcedures.sql b/db/StoredProcedures.sql
index 2dbbe4131..057b5310b 100644
--- a/db/StoredProcedures.sql
+++ b/db/StoredProcedures.sql
@@ -380,7 +380,8 @@ BEGIN
 			accounts.Login 		AS 'AccLogin', 
 			accounts.EMail 		AS 'AccEMail', 
 			user_roles.Type 	AS 'AccType',
-			user_roles.Role 	AS 'AccRole',	 
+			user_roles.RoleName	AS 'AccRole',	 
+			user_roles.Mark 	AS 'AccRoleMark',	 
 			accounts.isEnabled,
 			( accounts.ActivationCode IS NULL) AS 'isActivated',
 			accounts.UserAgent	
diff --git a/~dev_rating/application/bootstrap.php b/~dev_rating/application/bootstrap.php
index dda05c968..726fa28a6 100644
--- a/~dev_rating/application/bootstrap.php
+++ b/~dev_rating/application/bootstrap.php
@@ -1,4 +1,4 @@
-п»ї<?php defined('SYSPATH') or die('No direct script access.');
+<?php defined('SYSPATH') or die('No direct script access.');
 
 // -- Environment setup --------------------------------------------------------
 
@@ -103,7 +103,7 @@ if (isset($_SERVER['KOHANA_ENV']))
  * - boolean  expose      set the X-Powered-By header                        FALSE
  */
 Kohana::init(array(
-	'base_url'   => '/~dev_rating',
+	'base_url'   => '/~dev_rating/',
         'index_file' => FALSE
 ));
 
@@ -166,7 +166,7 @@ Route::set('handler', 'handler/<controller>/<action>(/<id>)')
                 {
                     if ($request->method() !== HTTP_Request::POST)
                     {
-                        // Данный маршрут выполним только для POST-запросов
+                        // Данный маршрут выполним только для POST-запросов изнутри фреймворка
                         return FALSE;
                     }
                 });
diff --git a/~dev_rating/application/classes/Controller/UserEnvi.php b/~dev_rating/application/classes/Controller/UserEnvi.php
index 403f53862..e162be9be 100644
--- a/~dev_rating/application/classes/Controller/UserEnvi.php
+++ b/~dev_rating/application/classes/Controller/UserEnvi.php
@@ -7,8 +7,7 @@ class Controller_UserEnvi extends Controller {
     {
         if(!User::instance()->isSignedIn())
         {
-            //$this->redirect('sign', 302);
-            throw new Kohana_Exception();
+            $this->redirect('sign', 302);
         }
         else 
         {
@@ -16,12 +15,13 @@ class Controller_UserEnvi extends Controller {
             // Проверка на 
             $this->UserInfo = User::instance()->getInfoAsArray();
             // Проверка на доступ к странице
-            $route = $this->request->route()->name();
-            $userMark = User::instance()->getUserMark();
-            $bitmask = Model_System::factory()->getBitmaskForRoute($route);
+            $route = Route::name($this->request->route());
+            $userMark = User::instance()->offsetGet('AccRoleMark');
+            $sysModel = new Model_System;
+            $bitmask = $sysModel->getBitmaskForRoute($route);
             if(!($bitmask & $userMark))
             {
-                throw HTTP_Exception::factory(403, 'Не пытайтесь попасть туда, куда попадать не следует.');
+                throw HTTP_Exception::factory(403, 'Не пытайтесь попасть туда, куда попадать не следует: '.$bitmask);
             }
         }
     }
diff --git a/~dev_rating/application/classes/Model/System.php b/~dev_rating/application/classes/Model/System.php
new file mode 100644
index 000000000..0ec6304bf
--- /dev/null
+++ b/~dev_rating/application/classes/Model/System.php
@@ -0,0 +1,10 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+  
+class Model_System extends Model
+{
+    public function getBitmaskForRoute($routeName)
+    {
+        $sql = "SELECT `GetBitmaskByPagename`('$routeName') AS `Bitmask`; ";
+        return DB::query(Database::SELECT, $sql)->execute()->get('Bitmask');
+    }
+}
diff --git a/~dev_rating/modules/account/classes/Kohana/User.php b/~dev_rating/modules/account/classes/Kohana/User.php
index 6e4cd2182..099d36657 100644
--- a/~dev_rating/modules/account/classes/Kohana/User.php
+++ b/~dev_rating/modules/account/classes/Kohana/User.php
@@ -87,7 +87,7 @@ class Kohana_User implements ArrayAccess {
     protected function completeSignIn($id, $passhash) {
         $userHash = $this->hash($id.Request::$user_agent.Request::$client_ip).$this->_config['hash_key'];
         $passhash = $this->hash($passhash.$this->_config['hash_key']);
-        //Cookie::set('userhash', $passhash);
+        Cookie::set('userhash', $passhash);
         $this->_userInfo = $this->_getInfoFromDB($id);
         $this->_session->regenerate();
         $this->_session->set('ID', $id);
@@ -218,8 +218,6 @@ class Kohana_User implements ArrayAccess {
     {
         $info = $this->_model->getPersonalInfoByID($id)->offsetGet(0);
         $info += $this->_model->getAccountInfoByID($id)->offsetGet(0);
-        $info['EMail'] = $info['E-Mail'];
-        unset($info['E-Mail']);
         return $info;
     }
 
-- 
GitLab