<?php
/**
 * Created by PhpStorm.
 * User: jaskokoyn
 * Date: 2/24/2015
 * Time: 1:18 PM
 */

include( '../inc/db.php' );
include( '../inc/functions.php' );

$response   =   array();

if(isset($_SESSION['loggedin'])){
    $response['confirmed'] = 1;
    die( json_encode($response) );
}

$code   =   secure($_POST['code']);
$codeCheckQuery =   $db->prepare("SELECT * FROM forgot_log WHERE fkey = :fkey AND expires > :ctime");
$codeCheckQuery->execute(array(
    ":fkey" =>  $code,
    ":ctime"    =>  time()
));
if($codeCheckQuery->rowCount() == 0){
    $response['confirmed'] = 1;
    die( json_encode($response) );
}
$codeCheckRow   =   $codeCheckQuery->fetch();

$response['confirmed'] =    2;
$response['email']     =    $codeCheckRow['email'];
die( json_encode($response) );