Файл: vkolhoze.com/loginAPI.php
Строк: 72
<?
include_once 'inc/start_sess.php';
include_once 'inc/functions.php';
if (isset($_POST['token'])) { $s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']); $_POST['loginAPI'] = true; }if (isset($_POST['token']))$users = json_decode($s, true);if (isset($_POST['token']) && !isset($user) && $users['network'] && $users['identity'] && $_POST['loginAPI'] == true)
{if (mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `type_reg` = '" . $users['network'] . "' AND `identity` = '" . $users['identity'] . "'"),0) == 0)
{
/*
================================
Имя к id и пол
================================
*/
if ($users['network'] == 'odnoklassniki')
$idi = 'ok';
else
$idi = null;
if ($users['sex'] == 2) $pol = 1;
else $pol = 0;
/*
================================
Создаем ник
================================
*/
$identity = $users['identity'];
$identity = str_replace('http://www.facebook.com', '', $identity);
$identity = str_replace('http://openid.yandex.ru', '', $identity);
$identity = str_replace('http://vk.com', '', $identity);
$identity = str_replace('http://odnoklassniki.ru', '', $identity);
$identity = str_replace('http://my.mail.ru/mail', '', $identity);
$identity = str_replace('/', '', $identity);
$identity = str_replace('.', '', $identity);
$identity = $idi . $identity;
/*
================================
Проверяем наличие ника в базе
если есть то добавляем случайное
число
================================
*/
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `nick` = '" . $identity . "'"),0)!=0)
$identity = $identity . '_' . mt_rand(0000, 9999);
/*
================================
Регаем пользователя
================================
*/
$pass = rand(1000,9999);
mysql_query("INSERT INTO `kolhoz_user` (`nick`, `password`, `date`, `date_last`, `pol`, `name`, `identity`, `type_reg`)
values('$identity', '" . md5($pass) . "', '$time', '$time', '" . $pol . "', '" . $users['first_name'] . "', '" . $users['identity'] . "', '" . $users['network'] . "')",$db);
$user=mysql_fetch_assoc(mysql_query("SELECT * FROM `kolhoz_user` WHERE `nick` = '". $identity ."' AND `password` = '". md5($pass) ."' LIMIT 1"));
$_SESSION['id_user']=$user['id'];
setcookie('id_user', $user['id'], time()+60*60*24*365);
header('Location: /user');
exit;
}else{
$user=mysql_fetch_assoc(mysql_query("SELECT * FROM `kolhoz_user` WHERE `type_reg` = '" . $users['network'] . "' AND `identity` = '" . $users['identity'] . "' LIMIT 1"));
$_SESSION['id_user'] = $user['id'];
setcookie('id_user', $user['id'], time() + 60 * 60 * 24 * 365);
mysql_query("UPDATE `kolhoz_user` SET `date_last` = " . time() . " WHERE `id` = '$user[id]' LIMIT 1");
header('Location: /user');
exit;
}
}
?>