<?php 
/*
Fungsi : Controller untuk user login
*/

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

class Login_mobile 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
	 */
	function __construct()
	{
		parent::__construct();
		$this->load->model('user/user_model', '', TRUE);
		$this->load->model('admin/admin_model', '', TRUE);
	}
	
	public function index()
	{	
		$this->do_login();
	}
	
	
	/* Cek login */
	function do_login()
	{
		$username = $this->input->post('email');
		$password = $this->input->post('password');
		//$username = "rony"; 
		//$password = "123456";
				
				$query_user_check = $this->user_model->check_login_mobile($username);	
				//Jika UID ditemukan maka check password
				if ($query_user_check->num_rows() > 0)
				{	
					$data_user = $query_user_check->result();
					foreach($data_user  as $row_user);

						if( $this->fungsi->decrypt1($row_user->pass) == $password)
						{   
							//Check apakah user di lock ?
							if( $row_user->lock == 1 )
							{
								//echo "Akun anda di lock";
								echo json_encode(Array('status' => 'failed'));
							}
							else
							{
								echo json_encode(Array('status' => 'success'));
							}
						}
						else
						{
							echo json_encode(Array('status' => 'failed'));
						}
				}
				else
				{	
					echo json_encode(Array('status' => 'failed'));
				}
	}
	
	/* Fungsi logout */
	function logout()
	{	
		$this->session->sess_destroy();
		$this->session->set_flashdata('message_err', 'Please login to enter system');
		redirect('user/user_login');
	}
	
}
?>