forked from CRSS/Website
fix: fix auth
This commit is contained in:
parent
c9eae5ea8c
commit
0689c5f844
20
auth.php
20
auth.php
|
@ -8,20 +8,26 @@
|
||||||
if(isset($_GET['code'])) {
|
if(isset($_GET['code'])) {
|
||||||
$res = $discord->validateCode($_GET['code']);
|
$res = $discord->validateCode($_GET['code']);
|
||||||
|
|
||||||
if(!$res->error) {
|
if(!$res['error']) {
|
||||||
$_SESSION['access_token'] = $res->access_token;
|
$_SESSION['access_token'] = $res['access_token'];
|
||||||
$_SESSION['refresh_token'] = $res->refresh_token;
|
$_SESSION['refresh_token'] = $res['refresh_token'];
|
||||||
$_SESSION['expires_in'] = $res->expires_in;
|
$_SESSION['expires_in'] = $res['expires_in'];
|
||||||
|
|
||||||
$guilds = $discord->getGuilds($res->access_token);
|
$guilds = $discord->getGuilds($res['access_token']);
|
||||||
|
|
||||||
if(!in_array('', $guilds)) {
|
$guildIds = array();
|
||||||
|
|
||||||
|
foreach ($guilds as $guild) {
|
||||||
|
$guildIds[] = $guild['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!in_array('1127731341283307520', $guildIds)) {
|
||||||
echo json_encode(array(
|
echo json_encode(array(
|
||||||
'error' => true,
|
'error' => true,
|
||||||
'error_description' => 'You are not in the CRSS guild.'
|
'error_description' => 'You are not in the CRSS guild.'
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$_SESSION['user'] = $discord->getUser($res->access_token);
|
$_SESSION['user'] = $discord->getUser($res['access_token']);
|
||||||
|
|
||||||
header('Location: /');
|
header('Location: /');
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUser($token): array {
|
function getUser($token): array {
|
||||||
$res = $this->curl->newRequest('get', '/users/@me')
|
$res = $this->curl->newRequest('get', 'https://discord.com/api/v10/users/@me')
|
||||||
->setHeader('Authorization', 'Bearer ' . $token)
|
->setHeader('Authorization', 'Bearer ' . $token)
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGuilds($token): array {
|
function getGuilds($token): array {
|
||||||
$res = $this->curl->newRequest('get', '/users/@me/guilds')
|
$res = $this->curl->newRequest('get', 'https://discord.com/api/v10/users/@me/guilds')
|
||||||
->setHeader('Authorization', 'Bearer ' . $token)
|
->setHeader('Authorization', 'Bearer ' . $token)
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue