<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Login extends CI_Controller {

	public function __construct(){
		parent::__construct();

		if(isset($_REQUEST['action']) && $_REQUEST['action']=='logout'){
			$this->session->unset_userdata('isUserLoggedIn');
		}

		if(isUserLoggedIn()==true){
			redirect(base_url('/dashboard'));
		}

		$this->load->model('LoginModel');
	}

	public function index()
	{
		$pageData = array(
			'header'=>array('pageTitle'=>'Login'),
		);

		if($this->input->post('fsEmail')!=""){
			$userDetails = $this->LoginModel->checkLogin($this->input->post('fsEmail'),$this->input->post('fsPassword'));
			if(count($userDetails) > 0){
				$this->session->set_userdata('isUserLoggedIn',$userDetails);
				redirect(base_url('/dashboard'));
			}else{
				$pageData['body']['isError'] = "The email & password is not matched.";
			}
		}
		loadView('login/login',$pageData,true);
	}

}
