<?php
// Include DB file for credentials and database connection 

include("db.php");

// User Create Method
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
	
	$return = array('success' => false, 'message' => 'Silence is gold');
	
	$data = json_decode(file_get_contents('php://input'), true);
	
	if($data['email'] != '' && $data['password'] != ''):
		
		$sql = "SELECT *  FROM `tbl_user` WHERE `email` = '".$data['email']."' AND `password` = '".md5($data['password'])."'";
		$result = $conn->query($sql);
		$rows  = [];
		
		if($result->num_rows == 1){ 
			$row = $result->fetch_assoc();
			
			
			switch($row['status']) {
				case '0':
					$return = array('success' => false, 'message' => 'Your account is not activated yet. Please contact administrator to activate your account.');
					break;
				case '2':
					$return = array('success' => false, 'message' => 'Your account has been deleted. Please contact administrator to restore account.');
					break;
				default:
					$return = array('success' => true, 'message' => 'Successfully Logged In!');
			} 			
			
			
			
		} else {
			$return = array('success' => false, 'message' => 'Snap! Log In Failed!');
		}			

	endif;
	echo json_encode($return);
	
}
