<?php
define('_IN_JOHNCMS', 1);
$rootpath = '../';
$headmod = 'login';
require('../incfiles/core.php');
if($user_id) header('Location: /?err');
$lng_reg = core::load_lng('registration');
$textl = $lng['registration'];
require('../incfiles/head.php');


$s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']); 
$user = json_decode($s, true); 

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `type_reg` = '" . $user['network'] . "' AND `identity` = '" . $user['identity'] . "'"),0) == 0)
{
echo'Учетной записи связанной с этой социальной сетью не обнаружено.';
require('../incfiles/end.php');
exit();
}else{
/*получаем данные юзера исходя из привязки к соц.сети*/
$res = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `type_reg` = '" . $user['network'] . "' AND `identity` = '" . $user['identity'] . "' LIMIT 1"));
// Установка данных сессии
$_SESSION['uid'] = $res['id'];
$_SESSION['ups'] = $res['password'];
mysql_query("UPDATE `users` SET `sestime` = '" . time() . "' WHERE `id` = '" . $res['id'] . "'");
$set_user = unserialize($res['set_user']);
if ($res['lastdate'] < (time() - 3600) && $set_user['digest']){
header('Location: ' . $set['homeurl'] . '/index.php?act=digest&last=' . $res['lastdate']);
}else{
header('Location: ' . $set['homeurl'] . '/index.php');}
}

require('../incfiles/end.php');
?>