Файл: tortuga/vk.php
Строк: 51
<?
require_once ('core/system.php');
$client_id = '5345109';
$client_secret = '8r5t356';
$redirect_uri = 'http://twgw.ru/vk.php';
$url = 'http://oauth.vk.com/authorize';
$params = array(
'client_id' => $client_id,
'redirect_uri' => $redirect_uri,
'response_type' => 'code'
);
echo $link = '<div class="player" ><a href="' . $url . '?' . urldecode(http_build_query($params)) . '"><img src="/img/vkauth.png"></a></div>';
if (isset($_GET['code'])) {
$result = false;
$params = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'code' => $_GET['code'],
'redirect_uri' => $redirect_uri
);
$token = json_decode(file_get_contents('https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($params))), true);
if (isset($token['access_token'])) {
$params = array(
'uids' => $token['user_id'],
'fields' => 'uid',
'access_token' => $token['access_token']
);
$userInfo = json_decode(file_get_contents('https://api.vk.com/method/users.get' . '?' . urldecode(http_build_query($params))), true);
if (isset($userInfo['response'][0]['uid'])) {
$userInfo = $userInfo['response'][0];
$result = true;
}
}
if ($result) {
$lo = mysql_query("SELECT COUNT(`id`) FROM `user` WHERE `nick` = 'vk-".$userInfo['uid']."'");
if (mysql_result($lo, 0) > 0) {
$info=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `nick` = 'vk-".$userInfo['uid']."' limit 1"));
setcookie('nick', $info['nick'], time() + 84600 * 365, '/');
setcookie('pass', $info['pass'], time() + 84600 * 365, '/');
header('Location: /game.php');
exit;
}
else{
$pass=mt_rand (1000, 9999);
$pass='vk-'.$pass.'';
$log='vk-'.$userInfo['uid'].'';
mysql_query("INSERT INTO `user` SET `nick` = '$log', `pass` = '$pass', `gold` = '0', `pol` = '1', `timereg` = '".time()."', `mana` = '1500', `max_mana` = '1500', `health` = '80', `max_health` = '80', `sila` = '80', `lovk` = '80', `zashit` = '80', `imp` = 'start', `impname` = 'Имп', `impstats` = '50'");
setcookie('nick', $log, time() + 84600 * 365, '/');
setcookie('pass', $pass, time() + 84600 * 365, '/');
header('Location: /moduls/start.php');
exit;
}
}
}
?>