-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-> Added so you can login using discord if you have your account linked
- Loading branch information
Showing
6 changed files
with
158 additions
and
26 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
include(__DIR__ . '/../../requirements/page.php'); | ||
if ($settings['enable_discord_link'] == "true") { | ||
if (isset($_GET['code'])) { | ||
$tokenUrl = 'https://discord.com/api/oauth2/token'; | ||
$data = array( | ||
'client_id' => $settings["discord_clientid"], | ||
'client_secret' => $settings["discord_clientsecret"], | ||
'grant_type' => 'authorization_code', | ||
'code' => $_GET['code'], | ||
'redirect_uri' => $appURL . '/auth/link/discord', | ||
'scope' => 'identify guilds email guilds.join' | ||
); | ||
$options = array( | ||
'http' => array( | ||
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | ||
'method' => 'POST', | ||
'content' => http_build_query($data), | ||
), | ||
); | ||
$context = stream_context_create($options); | ||
$result = file_get_contents($tokenUrl, false, $context); | ||
|
||
$accessToken = json_decode($result, true)['access_token']; | ||
|
||
$userUrl = 'https://discord.com/api/users/@me'; | ||
|
||
$options = array( | ||
'http' => array( | ||
'header' => "Authorization: Bearer $accessToken\r\n", | ||
'method' => 'GET', | ||
), | ||
); | ||
$context = stream_context_create($options); | ||
$result = file_get_contents($userUrl, false, $context); | ||
|
||
$userInfo = json_decode($result, true); | ||
echo $result; | ||
if (isset($userInfo)) { | ||
$conn->query("UPDATE `mythicaldash_users` SET `discord_linked` = 'true' WHERE `mythicaldash_users`.`api_key` = '" . mysqli_real_escape_string($conn, $_COOKIE['token']) . "';"); | ||
$conn->query("UPDATE `mythicaldash_users` SET `discord_id` = '" . $userInfo['id'] . "' WHERE `mythicaldash_users`.`api_key` = '" . mysqli_real_escape_string($conn, $_COOKIE['token']) . "';"); | ||
$conn->query("UPDATE `mythicaldash_users` SET `discord_username` = '" . $userInfo['username'] . "' WHERE `mythicaldash_users`.`api_key` = '" . mysqli_real_escape_string($conn, $_COOKIE['token']) . "';"); | ||
$conn->query("UPDATE `mythicaldash_users` SET `discord_global_username` = '" . $userInfo['global_name'] . "' WHERE `mythicaldash_users`.`api_key` = '" . mysqli_real_escape_string($conn, $_COOKIE['token']) . "';"); | ||
$conn->query("UPDATE `mythicaldash_users` SET `discord_email` = '" . $userInfo['email'] . "' WHERE `mythicaldash_users`.`api_key` = '" . mysqli_real_escape_string($conn, $_COOKIE['token']) . "';"); | ||
$conn->close(); | ||
header("location: /user/connections"); | ||
} else { | ||
header('location: /auth/link/discord'); | ||
} | ||
} else { | ||
$authorizeUrl = 'https://discord.com/api/oauth2/authorize?client_id=' . $settings["discord_clientid"] . '&redirect_uri=' . urlencode($appURL . '/auth/link/discord') . '&response_type=code&scope=' . urlencode('identify guilds email guilds.join'); | ||
header('Location: ' . $authorizeUrl); | ||
} | ||
} else { | ||
header("location: /dashboard?e=We are sorry but we don't provide support for discord link right now"); | ||
die(); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters