<?php 
session_start();
	require('config.php');
	require('conexao.php');

	if($_POST){
		$email = $_POST['login'];
		$pass  = md5($_POST['pass']);

		
		try {
			$query 		= $con->prepare("SELECT * FROM `login_admin` WHERE email= :email && pass= :pass");
			$query->bindParam(':email', $email);
			$query->bindParam(':pass',$pass);
			$exec 		= $query->execute();
			$result 	= $query->fetch(PDO::FETCH_ASSOC);
			

			switch ($query->rowCount()) {
				case '1':
					$_SESSION['loginAdmin']		=	$result['id'];
					$_SESSION['logInSucces']	= 	$result;
					?><script type="text/javascript">window.location.href="dashboard.php"</script><?

					break;
				
				case '0':
					$_SESSION['errorLog'] = "Login ou senha incorreta.";
					?><script type="text/javascript">window.history.back(-1);</script><?
					break;
			}

			


		} catch (Exception $e) {
			print_r($e);
		}
		

	}else{
		$_SESSION['errorLog'] = "Campos invalidos";
		?>
		<script type="text/javascript">window.history.back(-1);</script>
		<?
	}
	
?>