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

class Signin extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$data=null;
		$this->load->view('signin',$data);
		
	}
	public function validate()
	{
		$this->load->model('user_model');
		$email=$this->input->post('email');
		$password=$this->input->post('password');
		$this->db->select('*');
		$this->db->from('users');
		$this->db->where('password',md5($password));
		$this->db->where('email',$email);
		/*if(!empty($status)){
			$this->db->where('verified',$status);
		}*/
		$query = $this->db->get();
		$rowcount = $query->num_rows();
		if($rowcount==1 && $query->row()->verified==1){
			$this->session->set_userdata('user_id',$query->row()->id);
			$this->session->set_userdata('user_name',$query->row()->name);
			$this->session->set_userdata('is_login',true);
			$data['success'] = true;
            		//$data['errors'] = array('message' => 'Your account is not verified.');
		}elseif($rowcount==1 && $query->row()->verified==0){
			$data['success'] = false;
            		$data['message'] = 'Your account is not verified.';
		}else{
			$data['success'] = false;
            		$data['message'] = 'Email address / Password do not match.';
		}
		echo json_encode($data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
