first commit
This commit is contained in:
34
application/controllers/admin/force.php
Normal file
34
application/controllers/admin/force.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
|
||||
class Force_Controller extends Base_Admin_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
url::redirect('admin');
|
||||
}
|
||||
|
||||
public function login()
|
||||
{
|
||||
$user = ORM::factory('user',1);
|
||||
$admin = array();
|
||||
$admin['username'] = $user->username;
|
||||
$admin['last_success'] = $user->last_success;
|
||||
$admin['last_failed'] = $user->last_failed;
|
||||
$this->session->set('admin', $admin);
|
||||
$redirect = $this->session->get_once('admin_redirect', 'admin');
|
||||
#$redirect = $this->input->cookie('admin_redirect','admin');
|
||||
#cookie::delete('admin_redirect');
|
||||
url::redirect($redirect);
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
$this->session->delete('admin');
|
||||
url::redirect('admin');
|
||||
}
|
||||
}
|
||||
50
application/controllers/admin/page.php
Normal file
50
application/controllers/admin/page.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
|
||||
class Page_Controller extends Base_Admin_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->view->path = 'Strony';
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return $this->edit('home');
|
||||
}
|
||||
|
||||
public function edit($name = null)
|
||||
{
|
||||
$name = implode('/', $this->uri->argument_array());
|
||||
$page = new Page_Model();
|
||||
$page_view = new View('admin/page_edit');
|
||||
|
||||
$page = ORM::factory('page')->where('name', $name)->find();
|
||||
if (!$page->loaded)
|
||||
{
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
if($this->input->post())
|
||||
{
|
||||
$page->title = $this->input->post('page_title');
|
||||
$page->header = $this->input->post('page_header');
|
||||
$page->content = $this->input->post('page_content');
|
||||
$page->meta_description = $this->input->post('meta_description');
|
||||
$page->meta_keywords = $this->input->post('meta_keywords');
|
||||
$page->save();
|
||||
|
||||
if ($page->saved)
|
||||
{
|
||||
$this->session->set_flash('message','Strona została zapisana.');
|
||||
}
|
||||
url::redirect(url::current());
|
||||
}
|
||||
|
||||
$this->view->path .= $this->path_arrow . html::span_class($page->name, 'path_active');
|
||||
|
||||
$page_view->page = $page;
|
||||
$this->view->content = $page_view;
|
||||
$this->view->render(true);
|
||||
}
|
||||
}
|
||||
130
application/controllers/admin/user.php
Normal file
130
application/controllers/admin/user.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?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'))
|
||||
{
|
||||
print_r($_POST);
|
||||
//exit;
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
19
application/controllers/admin/welcome.php
Normal file
19
application/controllers/admin/welcome.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
|
||||
class Welcome_Controller extends Base_Admin_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$welcome_view = new View('admin/welcome');
|
||||
$this->view->path = 'Witamy';
|
||||
$welcome_view->title = Kohana::config('application.title');
|
||||
$this->view->content = $welcome_view;
|
||||
$this->view->render(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user