<?php

/*
 * checkUser.php
 * Se asegura que el usuario esté loggeado y carga si es necesario la variable
 * de sesión "user"
 */
set_include_path("../");
include_once("server/class/User.php");

@session_start();

$jsonParams = file_get_contents('php://input');
$data_back = json_decode($jsonParams, true);
$username = (isset($data_back['json_data']['user'])) ? addslashes(($data_back['json_data']['user'])) : null;
$password = (isset($data_back['json_data']['pass'])) ? addslashes(($data_back['json_data']['pass'])) : null;

try {
    // $username = filter_var($username, FILTER_SANITIZE_EMAIL);
    // $password = filter_var($password, FILTER_SANITIZE_STRING);
    //$username = 'americo.patetta@roman-group.com';
    //$password = 'Ap1647';
    $tempUser = new User($username, $password);
    if ($tempUser->isValidated()) {
        $_SESSION['user'] = $tempUser;
        $nodes["msg"] = "Ok";
    } else {
        //header("");
        $nodes['msg'] = "Error";
        $nodes['msgExplain'] = "Falló la autenticaci&oacute;n";
    }
} catch (Exception $e) {
    
}
header('Content-Type: application/json; charset=utf-8');
echo json_encode($nodes, JSON_FORCE_OBJECT);

?>


