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

class Login extends CI_Controller {
	function __construct(){
		parent::__construct();
		$this->master_m->redirect_login();
	}
	
	public function index()
	{
		$data['error']='';
		$data['konten']='login_v';
		$this->load->view('index_v',$data);
	}
	
	function cek_login(){
		$username=$this->master_m->InputPost('username');
		$password=$this->master_m->InputPost('password');
		
		$q=$this->db->get_where('user', array('username' => $username));
		if($q->num_rows()==1){
			if($this->master_m->verifyHashedPassword($password,$q->row('password'))==1){////password dan username benar
				if($q->row('id_jenis_user')==2){
					$q1=$this->db->get_where('data_kelurahan',array('id_data_kelurahan'=>$q->row('id_kelurahan')))->row('nama_kelurahan');
					$detail_login=str_replace('KELURAHAN ','',$q1);
				}else{
					$detail_login='';
				}
				$data=array('login'=>1,'id_user'=>$q->row('id_user'),'username'=>$username,'detail_login'=>$detail_login,'key'=>$q->row('key'),'id_jenis_user'=>$q->row('id_jenis_user'));
				$this->session->set_userdata($data);
				redirect(base_url('home'));
			}else{
				$data['error']='<div class="alert alert-danger" role="alert" align="center">USERNAME ATAU PASSWORD SALAH</div>';
				$data['konten']='login_v';
				$this->load->view('index_v',$data);
			}
		}else{
			$data['error']='<div class="alert alert-danger" role="alert" align="center">USERNAME ATAU PASSWORD SALAH</div>';
			$data['konten']='login_v';
			$this->load->view('index_v',$data);
		}
		
	}
}
