60 lines
2.1 KiB
PHP
60 lines
2.1 KiB
PHP
<?php defined('SYSPATH') or die('No direct script access.');
|
|
|
|
class Controller_Admin_Users extends Controller_Template {
|
|
public $template = 'admin/users/view';
|
|
protected $auth;
|
|
protected $user;
|
|
public function before() {
|
|
parent::before();
|
|
$this->auth = Auth::instance();
|
|
$this->user = $this->auth->get_user();
|
|
$this->session= Session::instance();
|
|
if ($this->auth->logged_in()){
|
|
if ($this->auth->logged_in(array('admin')) === FALSE) $this->template->error = "Недостаточно прав для внесения изменений.";
|
|
}
|
|
else{
|
|
$this->template->error = "Вы не зашли в систему.";
|
|
if ($this->request->action() != 'login') $this->request->redirect('admin/users/login');
|
|
}
|
|
}
|
|
|
|
public function action_view(){
|
|
$this->template->users = ORM::factory('user')->find_all()->as_array('id');
|
|
}
|
|
public function action_login() {
|
|
$this->template = new View('admin/users/login');
|
|
|
|
if($this->auth->logged_in()) return $this->request->redirect('admin/pages/view');
|
|
if ($_POST){
|
|
$user = ORM::factory('user');
|
|
$status = $this->auth->login($_POST['login'], $_POST['password']);
|
|
if ($status) $this->request->redirect('admin/pages/view');
|
|
else $this->template->error = "Неверный логин или пароль.";
|
|
}
|
|
}
|
|
public function action_logout() {
|
|
if ($this->auth->logout()) return $this->request->redirect('admin/users/login');
|
|
else $this->template->error = "Ошибка выхода пользователя.";
|
|
}
|
|
public function action_register() {
|
|
$this->template = new View('admin/users/register');
|
|
if ($_POST){
|
|
$model = ORM::factory('user');
|
|
$model->values(array(
|
|
'username' => $_POST['login'],
|
|
'email' => $_POST['email'],
|
|
'password' => $_POST['password'],
|
|
'password_confirm' => $_POST['password_confirm'],
|
|
));
|
|
try {
|
|
$model->save();
|
|
$model->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
|
|
$this->request->redirect('admin/users');
|
|
}
|
|
catch (ORM_Validation_Exception $e){
|
|
$this->template->error = "Ошибка проверки данных.";
|
|
}
|
|
}
|
|
}
|
|
}
|