You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
1.7 KiB

9 years ago
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
9 years ago
/**
* Login Class
*/
class Login extends CI_Controller
9 years ago
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
9 years ago
}
public function index()
9 years ago
{
// redirect if session exists
if($this->session->userdata('validated')){
redirect(base_url('/dashboard'));
9 years ago
}
9 years ago
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if (! ($this->input->post('username') AND $this->input->post('password')))
{
$this->_showlogin();
}
elseif ($this->form_validation->run() == FALSE)
{
$this->_showlogin('No username or password.');
} else {
// check login
$this->_checklogin();
}
}
private function _showlogin($errormsg = NULL)
9 years ago
{
// Load model
$this->load->model('Regio_model');
$regios = $this->Regio_model->get_regio_list();
// Arrange data
foreach ($regios as $regio) {
$data['regio'][$regio['id']] = $regio['naam'];
}
9 years ago
if ($errormsg)
{
$data['errormsg'] = $errormsg;
}
9 years ago
// Header
$this->load->view('header');
9 years ago
// login page
$this->load->view('login', $data);
9 years ago
// Footer
$this->load->view('footer');
}
private function _checklogin()
{
// Load model
$this->load->model('Login_model');
9 years ago
$userdata = $this->Login_model->check_user();
9 years ago
if ($userdata == FALSE) {
$this->_showlogin('Wrong username or password');
} else {
9 years ago
$this->_startsession($userdata);
}
}
9 years ago
private function _startsession($userdata)
{
// Start session with user data
$this->session->set_userdata($userdata);
// Redirect to dashboard
redirect(base_url('/dashboard'));
9 years ago
}
9 years ago
}
?>