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

class Login extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
		$this->load->library('session');
//        $this->check_isvalidated();
	}

	
	 public function index($msg = NULL){
        // Load our view to be displayed
        // to the user
        $data['msg'] = $msg;
        $this->load->view('admin/login', $data);
    }
    
    public function process(){
        // Load the model
        $this->load->model('admin/Login_model');
        // Validate the user can login
        $result = $this->Login_model->login();
//        $this->output->enable_profiler(TRUE);

//         Now we verify the result
        if(!$result){
//             If user did not validate, then show them login page again
            echo $result;
            $msg = '<div class="alert alert-danger">Invalid username and/or password. <span class="close" data-dismiss="alert">&times;</span></div><br />';
            $this->index($msg);
         } else{
//             If user did validate,
//             Send them to members area
            redirect('admin/Home');
        }
    }
	
    public function signout(){
        unset($_SESSION['admin']);
            // check session destroy or not. 
            redirect('admin/Login');
    }
	
}
