public function login()
{
$data['no_cache'] = TRUE;
if ($this->session->userdata('last_check')) {
$last_check = time() - $this->session->userdata('last_check');
if ($last_check < 3) {
sleep(2);
}
}
$this->session->set_userdata('last_check', time());
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'lang:lang_username', 'required');
$this->form_validation->set_rules('password', 'lang:lang_password', 'required');
$this->form_validation->set_error_delimiters('<p>', '</p>');
$this->template->set_layout(FALSE);
if ($this->form_validation->run() == false) {
$this->template->build('admin/login', $data);
} else {
$username = $this->input->post('username');
$password = $this->input->post('password');
$remember = $this->input->post('remember');
$login = $this->users_auth->login($username, $password, $remember);
if ($login !== TRUE) {
$data['error'] = $login;
$this->template->build('admin/login', $data);
} else {
$this->users_auth->redirect(TRUE);
}
}
}
/** * "Start" the application: * Analyze the URL elements and calls the according controller/method or the fallback */ public function __construct() { // create array with URL parts in $url $this->getUrlWithoutModRewrite(); // check for controller: no controller given ? then load start-page if (!$this->url_controller) { require APP . 'controllers/home.php'; $page = new Home(); $page->login(); } elseif (file_exists(APP . 'controllers/' . $this->url_controller . '.php')) { // here we did check for controller: does such a controller exist ? // if so, then load this file and create this controller // example: if controller would be "car", then this line would translate into: $this->car = new car(); require APP . 'controllers/' . $this->url_controller . '.php'; $this->url_controller = new $this->url_controller(); // check for method: does such a method exist in the controller ? if (method_exists($this->url_controller, $this->url_action)) { if (!empty($this->url_params)) { // Call the method and pass arguments to it call_user_func_array(array($this->url_controller, $this->url_action), $this->url_params); } else { // If no parameters are given, just call the method without parameters, like $this->home->method(); $this->url_controller->{$this->url_action}(); } } else { if (strlen($this->url_action) == 0) { // no action defined: call the default index() method of a selected controller $this->url_controller->index(); } else { // defined action not existent: show the error page require APP . 'controllers/error.php'; $page = new Error(); $page->index(); } } } else { require APP . 'controllers/error.php'; $page = new Error(); $page->index(); } }