<?php

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

class Login extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('Admin/Admin_model');
    }

    public function index()
    {
		if($this->session->userdata('loginedAdmin') && $this->session->userdata('loginedAdmin') == true)
		{
			redirect('Admin/Home_admin');	
		}
		
		if(!$this->input->post())
		{
			$this->load->view('Login');
		}
		else
		{
				$cek_login=$this->Admin_model->cek_login( 
				$this->input->post('username'), 
				$this->input->post('password')
				);

			if(!empty($cek_login))
				
			{
				$this->session->set_userdata('username', $cek_login -> username_admin);
				
				$this->session->set_userdata('loginedAdmin',true);
				redirect("Admin/Home_admin");
			}
			else 
			{
				redirect("/Login");
			}
		}
        
    } 
	
	public function logout()
    {
		$this->session->unset_userdata('loginedAdmin');
		redirect("/Admin/Login");
    } 
}

/* End of file Workflows.php */
/* Location: ./application/controllers/Workflows.php */
/* Please DO NOT modify this information : */
/* Generated by Harviacode Codeigniter CRUD Generator 2017-04-15 00:43:10 */
/* http://harviacode.com */