Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Added discord link
  • Loading branch information
NaysKutzu committed Oct 19, 2023
1 parent 846280c commit 3a8fe61
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 109 deletions.
24 changes: 17 additions & 7 deletions view/auth/discord.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php
include(__DIR__ . '/../requirements/page.php');
if ($settings['enable_discord_link'] == "true") {
if (isset($_GET['code'])) {
$tokenUrl = 'https://discord.com/api/oauth2/token';
Expand All @@ -19,11 +20,11 @@
);
$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",
Expand All @@ -32,13 +33,22 @@
);
$context = stream_context_create($options);
$result = file_get_contents($userUrl, false, $context);

$userInfo = json_decode($result, true);
echo $result;
if (isset($userInfo)) {

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');
$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 {
Expand Down
5 changes: 3 additions & 2 deletions view/requirements/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class="template-customizer-theme-css" />
<link rel="stylesheet" href="<?= $appURL ?>/assets/vendor/libs/select2/select2.css" />
<script src="<?= $appURL ?>/assets/vendor/js/helpers.js"></script>
<script src="<?= $appURL ?>/assets/vendor/js/template-customizer.js"></script>


<script src="<?= $appURL ?>/assets/js/config.js"></script>
<link rel="stylesheet" href="<?= $appURL ?>/assets/css/preloader.css" />
<style>
Expand All @@ -64,6 +62,9 @@ class="template-customizer-theme-css" />
if ($settings['customcss_enabled'] == 'true') {
?>
<style type="text/css">
#template-customizer .template-customizer-open-btn {
visibility: hidden;
}
<?= $settings['customcss_code'] ?>
</style>
<?php
Expand Down
122 changes: 22 additions & 100 deletions view/user/connections.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,9 @@
<?php
include(__DIR__ . '/../requirements/page.php');
include(__DIR__ . '/../../include/php-csrf.php');
$csrf = new CSRF();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($csrf->validate('profile-form')) {
if (isset($_POST['edit_user'])) {
$userdb = $conn->query("SELECT * FROM mythicaldash_users WHERE api_key = '" . $_COOKIE['token'] . "'")->fetch_array();
$username = mysqli_real_escape_string($conn, $_POST['username']);
$firstName = mysqli_real_escape_string($conn, $_POST['firstName']);
$lastName = mysqli_real_escape_string($conn, $_POST['lastName']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$avatar = mysqli_real_escape_string($conn, $_POST['avatar']);
if (!$username == "" || $firstName == "" || $lastName == "" || $email == "" || $avatar == "") {
if (!$userdb['username'] == $username || !$email == $userdb['email']) {
$check_query = "SELECT * FROM mythicaldash_users WHERE username = '$username' OR email = '$email'";
$result = mysqli_query($conn, $check_query);
if (mysqli_num_rows($result) > 0) {
header('location: /user/profile?e=Username or email already exists. Please choose a different one');
die();
}
} else {
$conn->query("UPDATE `mythicaldash_users` SET `username` = '" . $username . "' WHERE `mythicaldash_users`.`api_key` = '" . $_COOKIE['token'] . "';");
$conn->query("UPDATE `mythicaldash_users` SET `first_name` = '" . $firstName . "' WHERE `mythicaldash_users`.`api_key` = '" . $_COOKIE['token'] . "';");
$conn->query("UPDATE `mythicaldash_users` SET `last_name` = '" . $lastName . "' WHERE `mythicaldash_users`.`api_key` = '" . $_COOKIE['token'] . "';");
$conn->query("UPDATE `mythicaldash_users` SET `avatar` = '" . $avatar . "' WHERE `mythicaldash_users`.`api_key` = '" . $_COOKIE['token'] . "';");
$conn->query("UPDATE `mythicaldash_users` SET `email` = '" . $email . "' WHERE `mythicaldash_users`.`api_key` = '" . $_COOKIE['token'] . "';");
$conn->close();
header('location: /user/profile?s=We updated the user settings in the database');
}
} else {
header('location: /user/profile?e=Please fill in all the info');
die();
}
}
} else {
header('location: /user/profile?e=CSRF Verification Failed');
}
if (isset($_GET['unlink_discord'])) {
$conn->query("UPDATE `mythicaldash_users` SET `discord_linked` = 'false' WHERE `mythicaldash_users`.`api_key` = '" . mysqli_real_escape_string($conn, $_COOKIE['token']) . "';");
$conn->close();
header('location: /user/connections');
}
?>
<!DOCTYPE html>
Expand Down Expand Up @@ -101,13 +68,15 @@ class="ti-xs ti ti-link me-1"></i> Connections</a>
<?php

if ($userdb['discord_linked'] == "true") {
?>
<small class="text-muted"><?= $userdb['discord_username']?></small>
?>
<small class="text-muted">
<?= $userdb['discord_username'] ?>
</small>
<?php
} else {
?>
<small class="text-muted">Not Connected</small>
<?php
<?php
}
?>

Expand All @@ -117,18 +86,19 @@ class="ti-xs ti ti-link me-1"></i> Connections</a>
if ($userdb['discord_linked'] == "true") {
?>
<div class="col-sm-5 text-sm-end mt-sm-0 mt-2">
<button class="btn btn-label-danger btn-icon waves-effect"><i
class="ti ti-trash ti-sm"></i></button>
<a href="/user/connections?unlink_discord=yes" class="btn btn-label-danger btn-icon waves-effect"><i
class="ti ti-trash ti-sm"></i></a>
</div>
<?php
<?php
} else {
?>
<div class="col-sm-5 text-sm-end mt-sm-0 mt-2">
<button class="btn btn-label-secondary btn-icon waves-effect">
<a href="/auth/link/discord"
class="btn btn-label-secondary btn-icon waves-effect">
<i class="ti ti-link ti-sm"></i>
</button>
</a>
</div>
<?php
<?php
}
?>

Expand All @@ -142,24 +112,14 @@ class="ti ti-trash ti-sm"></i></button>
<div class="flex-grow-1 row">
<div class="col-sm-7">
<h6 class="mb-0">GitHub</h6>
<?php

if ($userdb['discord_linked'] == "true") {

} else {
?>
<small class="text-muted">Not Connected</small>
<?php
}
?>

<small class="text-muted">Soon</small>
</div>

<div class="col-sm-5 text-sm-end mt-sm-0 mt-2">
<!--<div class="col-sm-5 text-sm-end mt-sm-0 mt-2">
<button class="btn btn-label-secondary btn-icon waves-effect">
<i class="ti ti-link ti-sm"></i>
</button>
</div>
</div>-->
</div>
</div>
<div class="d-flex mb-3">
Expand All @@ -170,52 +130,14 @@ class="ti ti-trash ti-sm"></i></button>
<div class="flex-grow-1 row">
<div class="col-sm-7">
<h6 class="mb-0">Google</h6>
<?php

if ($userdb['discord_linked'] == "true") {

} else {
?>
<small class="text-muted">Not Connected</small>
<?php
}
?>

</div>

<div class="col-sm-5 text-sm-end mt-sm-0 mt-2">
<button class="btn btn-label-secondary btn-icon waves-effect">
<i class="ti ti-link ti-sm"></i>
</button>
</div>
</div>
</div>
<div class="d-flex mb-3">
<div class="flex-shrink-0">
<img src="https://avatars.githubusercontent.com/u/117385445"
alt="mythicalsystems" class="me-3" height="55">
</div>
<div class="flex-grow-1 row">
<div class="col-sm-7">
<h6 class="mb-0">MythicalSystems</h6>
<?php

if ($userdb['discord_linked'] == "true") {

} else {
?>
<small class="text-muted">Not Connected</small>
<?php
}
?>

<small class="text-muted">Soon</small>
</div>

<div class="col-sm-5 text-sm-end mt-sm-0 mt-2">
<!--<div class="col-sm-5 text-sm-end mt-sm-0 mt-2">
<button class="btn btn-label-secondary btn-icon waves-effect">
<i class="ti ti-link ti-sm"></i>
</button>
</div>
</div>-->
</div>
</div>
</div>
Expand Down

0 comments on commit 3a8fe61

Please sign in to comment.