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

class Login extends CI_Controller
{

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

	public function index()
	{
		$data = array(
			'page_title' => 'Sign in'
		);
		$this->load->view('backend/login/index',$data);
	}

	public function proses()
	{
		$user = $this->input->post('user', TRUE);
		$pass = $this->input->post('pass', TRUE);

		// cek username & password
		if(($user == 'admin' && $pass == '1234') || ($user == 'dirut' && $pass == '1234') || ($user == 'pklo' && $pass == '1234') || ($user == 'diryan' && $pass == '1234') || ($user == 'sdm' && $pass == '1234')) {
		
			// membuat session
					$this->session->set_userdata('username', $user);
					$this->session->set_userdata('is_login', TRUE);

					// redirect ke admin
					redirect(base_url('dashboard'));
		} else {

			// jika username salah
			$this->session->set_flashdata('failed', 'Username atau password salah !');
			redirect(base_url('login'));
		}
	}

	public function logout()
	{
		$this->session->unset_userdata('username');
		$this->session->unset_userdata('is_login');

		$this->session->sess_destroy();
		redirect(base_url('login'));
	}
}
