<?php namespace App\Controllers;

use App\Models\UsersModel;

class Login extends BaseController
{	
	
	public function index()
	{   		
		return view('pages/login');
	}
	
	public function signout(){
		$session = session();	
		$session->destroy();
		return view('pages/login');
	}
	
	public function processlogin(){
		$email = $this->request->getPost('email');
		$password = $this->request->getPost('password');
			
		$session = session();		
		$userModel = new UsersModel();
		$usr = $userModel->asObject()->where('email',$email)->findAll();
		//print_r($usr);
		if($usr!=false){
			if($usr[0]->password==md5($password)){
				
				$session->set('user',$usr[0]);
				$session->set('islogin',true);
				$data['user'] = $usr[0];
				return view('pages/main-detail',$data);
			}else{
				$data['error'] = 'Password salah';
				return view('pages/login',$data);
			}
		}else{
			$data['error'] = 'Email tidak ditemukan';
			return view('pages/login',$data);
		}
				
	}

	//--------------------------------------------------------------------

}
