<?php defined('SYSPATH') or die('No direct script access.');
/*
* Авторизация
*/
class Controller_Index_Auth extends Controller_Index {
public function action_index() {
$this->action_login();
}
public function action_login() {
if(Auth::instance()->logged_in()) {
$this->request->redirect('account');
}
if (isset($_POST['submit'])){
$data = Arr::extract($_POST, array('username', 'password', 'remember'));
$status = Auth::instance()->login($data['username'], $data['password'], (bool) $data['remember']);
if ($status){
if(Auth::instance()->logged_in('admin')) {
$this->request->redirect('admin');
}
$this->request->redirect('account');
}
else {
$errors = array(Kohana::message('auth/user', 'no_user'));
}
}
$content = View::factory('index/auth/v_auth_login')
->bind('errors', $errors)
->bind('data', $data);
// Выводим в шаблон
$this->template->title = 'Вход';
$this->template->page_title = 'Вход';
$this->template->block_center = array($content);
}
public function action_register() {
if (isset($_POST['submit'])){
$data = Arr::extract($_POST, array('username', 'password', 'first_name', 'password_confirm', 'email'));
$users = Model::factory('user');
try {
$users->create_user($_POST, array(
'username',
'first_name',
'password',
'email',
));
$role = ORM::factory('role')->where('name', '=', 'login')->find();
$users->add('roles', $role);
$this->action_login();
$this->request->redirect('account');
}
catch (ORM_Validation_Exception $e) {
$errors = $e->errors('auth');
}
}
$content = View::factory('index/auth/v_auth_register')
->bind('errors', $errors)
->bind('data', $data);
// Выводим в шаблон
$this->template->title = 'Регистрация';
$this->template->page_title = 'Регистрация';
$this->template->block_center = array($content);
}
public function action_logout() {
if(Auth::instance()->logout()) {
$this->request->redirect();
}
}
}
<?php defined('SYSPATH') or die('No direct script access.');
class Model_User extends Model_Auth_User {
public function labels()
{
return array(
'username' => 'Логин',
'email' => 'E-mail',
'first_name' => 'ФИО',
'password' => 'Пароль',
'password_confirm' => 'Повторить пароль',
);
}
public function rules()
{
return array(
'username' => array(
array('not_empty'),
array('min_length', array(':value', 4)),
array('max_length', array(':value', 32)),
array('regex', array(':value', '/^[-\pL\pN_.]++$/uD')),
array(array($this, 'username_available'), array(':validation', ':field')),
),
'first_name' => array(
array('not_empty'),
array('min_length', array(':value', 2)),
array('max_length', array(':value', 32)),
),
'password' => array(
array('not_empty'),
),
'email' => array(
array('not_empty'),
array('min_length', array(':value', 4)),
array('max_length', array(':value', 127)),
array('email'),
array(array($this, 'email_available'), array(':validation', ':field')),
),
);
}
}
Версия коханы 3.1.2 Пробовал этот код в версии 3.2, 3.3, добавив в bootstrap.php Cookie::$salt. Все равно не работает. Буду рад любой помощи