<?php 

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

$response = array();

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

if(!empty($_POST['username']) and !empty($_POST['email']) and !empty($_POST['password'])) {

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

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

		
			if($result == 1){
				
				$response['error'] = false;
				$response['message'] = "User regiseterd successfully";	

			}elseif($result == 2){
				$response['error'] = true;
				$response['message'] = "Some error occured. Please retry again";
			}elseif($result == 0){
					$response['error'] = true;
				$response['message'] = "User already exist/Please choose a different email";
			}
		}else{
			$response['error'] = true;
			$response['message'] = "Required fields are missing";
		}

		}else{
			$response['error'] = true;
			$response['message'] = "Required fields are missing";
		}

			
}else{
	$response['error'] = true;
	$response['message'] = "Invalid Request";
}

echo json_encode($response);


 ?>