128 lines
3.8 KiB
PHP
128 lines
3.8 KiB
PHP
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
|
|
|
class User_Controller extends Base_Admin_Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
// $this->redirect = 'admin/password';
|
|
// $this->message->password_success = 'Hasło zostało zmienione.';
|
|
// $this->message->password_error = 'Błąd! Wpisz poprawne dane!';
|
|
}
|
|
public function index()
|
|
{
|
|
return $this->login();
|
|
}
|
|
|
|
public function login()
|
|
{
|
|
if($this->session->get('admin'))
|
|
{
|
|
url::redirect('admin');
|
|
}
|
|
$admin_title = $this->view->title;
|
|
$this->view = new View('admin_login');
|
|
$this->view->title = $admin_title;
|
|
|
|
if($this->input->post() && $this->input->post('zaloguj'))
|
|
{
|
|
$user = ORM::factory('user')->find($this->input->post('username'));
|
|
if ($user->loaded) {
|
|
if ($user->is_active && $user->sha1_password == sha1($user->salt . $this->input->post('password'))) {
|
|
$admin = array();
|
|
$admin['id'] = $user->id;
|
|
$admin['role'] = $user->role;
|
|
$admin['username'] = $user->username;
|
|
$admin['email'] = $user->email;
|
|
$admin['last_success'] = $user->last_success;
|
|
$admin['last_failed'] = $user->last_failed;
|
|
$this->session->set('admin', $admin);
|
|
|
|
$user->last_success = date('Y-m-d H:i:s');
|
|
$user->save();
|
|
$redirect = $this->session->get_once('admin_redirect', 'admin');
|
|
#$redirect = $this->input->cookie('admin_redirect','admin');
|
|
#cookie::delete('admin_redirect');
|
|
url::redirect($redirect);
|
|
}
|
|
else
|
|
{
|
|
$user->last_failed = date('Y-m-d H:i:s');
|
|
$user->save();
|
|
url::redirect('admin/login');
|
|
}
|
|
}
|
|
else {
|
|
url::redirect('admin/login');
|
|
}
|
|
}
|
|
|
|
$this->view->render(true);
|
|
#exit;
|
|
}
|
|
|
|
public function logout()
|
|
{
|
|
$this->session->delete('admin');
|
|
url::redirect('admin');
|
|
}
|
|
|
|
public function password()
|
|
{
|
|
$password_view = new View('admin/password');
|
|
$this->view->path = 'Administracja' . $this->path_arrow . html::span_class('Zmiana hasła', 'path_active');
|
|
|
|
$user = ORM::factory('user')->find($this->admin['id']);
|
|
|
|
if($this->input->post())
|
|
{
|
|
#$_POST['email'] = Kohana::config('application.email');
|
|
|
|
$post = new Validation($this->input->post());
|
|
$post->pre_filter('trim')
|
|
->add_rules('username', 'required', 'length[3,20]', 'chars[a-zA-Z0-9_.]')
|
|
->add_rules('email', 'required', 'length[5,50]', 'valid::email') # ,'valid::email_domain'
|
|
->add_rules('password', 'required', 'length[3,40]')
|
|
->add_rules('password2', 'matches[password]');
|
|
|
|
|
|
if($post->validate())
|
|
{
|
|
$salt = md5(rand(100000,999999). $post->username . $post->email);
|
|
$user->username = $post->username;
|
|
$user->email = $post->email;
|
|
$user->salt = $salt;
|
|
$user->sha1_password = sha1($salt . $post->password);
|
|
$user->password_date = date('Y-m-d H:i:s');
|
|
|
|
if($user->username_not_exists() AND $user->email_not_exists())
|
|
{
|
|
$user->save();
|
|
if($user->saved)
|
|
{
|
|
$admin = $this->session->get('admin');
|
|
$admin['username'] = $post->username;
|
|
$this->session->set('admin', $admin);
|
|
$this->session->set_flash('message', $this->message->password_success);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$this->session->set_flash('message', $this->message->exist_error);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
$this->session->set_flash('message', $this->message->password_error);
|
|
}
|
|
url::redirect('admin/password');
|
|
}
|
|
$password_view->username = $user->username;
|
|
$password_view->email = $user->email;
|
|
|
|
$this->view->content = $password_view;
|
|
$this->view->render(true);
|
|
}
|
|
|
|
} |