<?php session_start();?>
<?php include("../includes/connect.php"); ?>
<?php
	$email = isset($_POST['user']) ? trim($_POST['user']) : '';
	$pass  = isset($_POST['pass']) ? trim($_POST['pass']) : '';

	if(empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)){
		echo 0;
		exit;
	}
	if(empty($pass) || !ctype_print($pass)){
		echo 0;
		exit;
	}

	$stmt = $smeConn->prepare("SELECT * FROM users WHERE email=? LIMIT 1");
	$stmt->bind_param("s", $email);
	$stmt->execute();
	$result = $stmt->get_result();

	if($result->num_rows > 0){
		$row = $result->fetch_assoc();
		if(password_verify($pass, $row['password'])){
			$_SESSION['email']    = $row['email'];
			$_SESSION['first']    = $row['first'];
			$_SESSION['id']       = $row['id'];
			$_SESSION['userType'] = $row['usertype'];
			echo $row['usertype'];
		} else {
			echo 0;
		}
	} else {
		echo 0;
	}
?>