<?php

require_once '../includes/DbOperations.php';

$response = array();

if($_SERVER['REQUEST_METHOD'] == 'POST'){


	if(!empty($_POST['username']) and !empty($_POST['email']) and !empty($_POST['code']) and !empty($_POST['password'])) {
		if(isset($_POST['username']) and isset($_POST['email']) and isset($_POST['code']) and isset($_POST['password'])) {
			$db =  new DbOperations();

			$result = $db -> checkuserreset( $_POST['username'],$_POST['email'],$_POST['code'],$_POST['password']);
	

	if($result == 1){
				
				$response['error'] = false;
				$response['message'] = "Password Change Was Successful.";	
			}
			elseif($result == 0){
				$response['error'] = true;
				$response['message'] = "Wrong details Entered. <a href='passreset.php'> Click here to try again.";
			}elseif($result==2){
				$response['error'] = true;
				$response['message'] = "Error Occured.";
			}

	}else{
		echo "no";
	}
}else{
			$response['error'] = true;
			$response['message'] = "Required fields are missing. <a href='passreset.php'> Click here to try again";
		}
}else{
	$response['error'] = true;
	$response['message'] = "Invalid Request";
}

echo json_encode($response);
?>