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

class Authentication extends CI_Controller {

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

	public function login()
	{

        if($this->session->userdata('admin'))
		{
            //redirect('admin/home');
           // exit();
        }

		$this->load->model('mod_authentication');
		$this->load->helper('form','url');
		$this->load->library('form_validation');

        $this->form_validation->set_rules('username','Username', 'trim|required|max_length[45]');
        $this->form_validation->set_rules('password','Password', 'trim|required|max_length[45]');

		if($this->form_validation->run()== TRUE)
		{
            $username = $this->input->post('username');
            $password = sha1($this->input->post('password'));
            $remember = $this->input->post('remember');

            if($this->mod_authentication->login($username, $password))
			{
               redirect('admin/booking_list');
               exit();
            }
            $this->session->set_userdata('ms_error','Invalid account!');
        }

        $this->load->view('authentication/login');
    }

	

	public function logout()
	{
		$this->session->unset_userdata('admin');
        $this->session->unset_userdata('userName');
		$this->session->unset_userdata('role');
		//$this->session->unset_userdata('STATUS_ACTIVATED');
        $this->session->unset_userdata('userId');
       	redirect('authentication/login');
		exit();
    }

		

		

		

		

		

}

