forked from nightmarez/Casino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvk-auth.php
78 lines (65 loc) · 2.34 KB
/
vk-auth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
require_once('config/vk-config.php');
require_once('utils.php');
if (isset($_GET['code']))
{
$code = $_GET['code'];
$token = getVkToken($code);
$login = 'vk:' . $token['user_id'];
$pass = $token['access_token'];
$db = new PdoDb();
$db->beginTransaction();
if (!isUserExists($login))
{
$req = $db->prepare('INSERT INTO `users` (`login`, `pass`, `level`, `activated`, `sms`, `money`, `lobbyaccess`) VALUES (:login, :pass, 2, 1, "", 10000, 1);');
$req->bindParam(':login', $login, PDO::PARAM_STR);
$req->bindParam(':pass', $pass, PDO::PARAM_STR);
$req->execute();
setUserCookies($login, $pass);
header('Location: /');
}
else
{
$req = $db->prepare('UPDATE `users` SET `pass`=:pass WHERE `login`=:login;');
$req->bindParam(':login', $login, PDO::PARAM_STR);
$req->bindParam(':pass', $pass, PDO::PARAM_STR);
$req->execute();
setUserCookies($login, $pass);
header('Location: /');
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
$params = array(
'uids' => explode(':', $login)[1],
'fields' => 'photo_big',
'access_token' => $pass
);
$userInfo = json_decode(file_get_contents('https://api.vk.com/method/users.get' . '?' . urldecode(http_build_query($params))), true);
$url = $userInfo['response'][0]['photo_big'];
$tmp = 'thmbs/tmp:' . $login . '.' . end(explode('.', $url));
file_put_contents($tmp, fopen($url, 'r'));
$dst = 'thmbs/' . $login . '.jpg';
if (file_exists($dst))
{
unlink($dst);
}
list($width, $height) = getimagesize($tmp);
$thumb = imagecreatetruecolor(64, 64);
$source = imagecreatefromjpeg($tmp);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, 64, 64, $width, $height);
imagejpeg($thumb, $dst);
imagedestroy($thumb);
imagedestroy($source);
unlink($tmp);
//////////////////////////////////////////////////////////////////////////////////////////////////////////
$fullName = htmlspecialchars($userInfo['response'][0]['first_name'] . ' ' . $userInfo['response'][0]['last_name']);
$req = $db->prepare('UPDATE `users` SET `fullname`=:fullName WHERE `login`=:login;');
$req->bindParam(':login', $login, PDO::PARAM_STR);
$req->bindParam(':fullname', $fullname, PDO::PARAM_STR);
$req->execute();
$db->commit();
}
else
{
header('Location: ' . genVkAuthLink());
}
?>