@ -13,6 +13,31 @@ class Login extends CI_Controller
@@ -13,6 +13,31 @@ class Login extends CI_Controller
}
public function index()
{
// redirect if session exists
$this->load->library('session');
if(! $this->session->userdata('validated')){
redirect('/dashboard');
}
$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)
{
// Load model
$this->load->model('Regio_model');
@ -23,20 +48,16 @@ class Login extends CI_Controller
@@ -23,20 +48,16 @@ class Login extends CI_Controller
$data['regio'][$regio['id']] = $regio['naam'];
}
if ($errormsg)
{
$data['errormsg'] = $errormsg;
}
// Header
$this->load->view('header');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE)
{
// login page
$this->load->view('login', $data);
} else {
// check login
$this->_checklogin();
}
// Footer
$this->load->view('footer');
@ -46,15 +67,25 @@ class Login extends CI_Controller
@@ -46,15 +67,25 @@ class Login extends CI_Controller
{
// Load model
$this->load->model('Login_model');
$logincheck = $this->Login_model->check_user();
$userdata = $this->Login_model->check_user();
if ($logincheck == FALSE) {
echo "No user " ;
if ($userdata == FALSE) {
$this->_showlogin('Wrong username or password') ;
} else {
echo "Ok" ;
$this->_startsession($userdata) ;
}
}
private function _startsession($userdata)
{
// Start session with user data
$this->load->library('session');
$this->session->set_userdata($userdata);
// Redirect to dashboard
redirect('/dashboard');
}
}
?>