<?php
session_start();
include("../SystemController/DbConnection.php");

$db_handle = new DbConnection();

$id = $_SESSION['id'];

if(isset($_POST['otp_code'])){
	$otp = $_POST['otp_code'];

	if($otp == ''){
	echo 'no_code';
	}else{
	$code =	$db_handle->runBaseQuery("SELECT * FROM users WHERE id = $id");

	$time = $code[0]['time'];

	$current_time = time();
	
	

	if($current_time - $time > 3600){ 

		echo 'expired';
	}elseif($otp != $code[0]['code']){

	echo 'invalid_code';
}else{
    $_SESSION['loggedin'] = true;
	echo 'success';
}
	}

}

?>