<?php

//include_once 'cache.arquivo.php';
require_once 'CacheArquivo.php';
require_once 'CacheSessao.php';
require_once 'Connection.php';
require_once 'User.php';
$c = new Connection();
$u = new User();
$cacheArquivo = new CacheArquivo();
$cacheSessao = new CacheSessao();
$UsId = $u->GetUserIdByUserName($_REQUEST['userName']);
$u->UserId($UsId);
$Contacts = $u->GetAllContacts($UsId);
$valor = json_encode($Contacts);
$cacheArquivo->set_valor($UsId, $valor);
if ($UsId > 0) {
    $cacheSessao->set_valor('USERID', $UsId);
    $cacheSessao->set_valor('USERNAME', $_REQUEST['userName']);
} else {
    $cacheSessao->set_valor('USERID');
    $cacheSessao->set_valor('USERNAME');
}
$u->UserName($_REQUEST['userName']);
$u->Password($_REQUEST['password']);
$res = $u->VerifyLogin();
if ($res) {
    echo '<html>';
    echo '<script language="JavaScript">';
    echo 'window.location="Main.php"';
    echo '</script>';