Answer the question
In order to leave comments, you need to log in
How to solve the problem with ORM authorization in Kohana 3.3.4?
There was a problem with ORM authorization in Kohana 3.3.4 Created a base controller for authorization Controller_Index_Auth which is an inheritor of the Controller_Index class, which in turn is from the base controller Controller_Base . In the base controller, the $auth field stores the Auth::instance() framework object .
base controller code
class Controller_Base extends Controller_Template {
public $user;
public $auth;
public $cache;
public $session;
public function before() {
parent::before();
I18n::lang('ru');
$settings = Kohana::$config->load('settings');
Cookie::$salt = 'asd12d2';
Session::$default = 'cookie';
$this->cache = Cache::instance('file');
$this->auth = Auth::instance();
$this->user = $this->auth->get_user();
$this->session = Session::instance();
}
}
class Controller_Index_Auth extends Controller_Index {
public function action_index() {
$this->action_login();
}
public function action_login() {
if(Auth::instance()->logged_in()) {
$this->redirect('account');
}
if (isset($_POST['submit'])){
$data = Arr::extract($_POST, array('username', 'password', 'remember'));
$status = $this->auth->login($data['username'], $data['password'], (bool) $data['remember']);
//$role = $this->auth->logged_in();
// var_dump($role);
// $user = $this->auth->get_user();
// var_dump($user);
if ($status){
if($this->auth->logged_in('admin')) {
$this->redirect('admin');
}
$this->redirect('account');
}
else {
$errors = array(Kohana::message('auth/user', 'no_user'));
}
}
// ...
}
//...
}
class Controller_Index_Account extends Controller_Index {
public function before(){
parent::before();
if (!$this->auth->logged_in()) { // здесь идет проверка
$this->redirect('login');
}
$account_menu = Widget::load('menuaccount');
// Выводим в шаблон
$this->template->block_right = null;
$this->template->block_left = array($account_menu);
}
// ...
}
return array(
//'driver' => 'file',
'driver' => 'orm',
'hash_method' => 'sha256',
'hash_key' => 'asjdhas6f2e12kas',
'lifetime' => 1209600,
'session_key' => 'auth_user',
// Username/password combinations for the Auth File driver
'users' => array(
// 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
'user'=>'857c303e1102231b7e4a27aaa0a2dd6495aa2510c0290781614581f483efb11b'
),
);
Answer the question
In order to leave comments, you need to log in
1. Initialize session:
before you do:
$this->auth = Auth::instance();
$this->user = $this->auth->get_user();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question