diff --git a/auth.php b/auth.php
index c5f70a9..892b809 100644
--- a/auth.php
+++ b/auth.php
@@ -21,17 +21,22 @@
$guildIds[] = $guild['id'];
}
- if(!in_array('1127731341283307520', $guildIds)) {
+ if(!in_array('1127731341283307520', $guildIds) || !in_array('1195393418151596032', $guildIds)) {
echo json_encode(array(
'error' => true,
- 'error_description' => 'You are not in the CRSS guild.'
+ 'error_description' => 'You are not in any of CRSS\'s guilds.'
));
} else {
$_SESSION['user'] = $discord->getUser($res['access_token']);
$mysql->createUserRecord($_SESSION['user']);
-
- header('Location: /');
+
+
+ if (isset($_GET['state'])) {
+ header('Location: ' . $_GET['state']);
+ } else {
+ header('Location: /');
+ }
}
} else {
echo json_encode($res);
diff --git a/index.php b/index.php
index f5978f9..cf34a70 100644
--- a/index.php
+++ b/index.php
@@ -1,5 +1,5 @@
addGlobal('user', $_SESSION['user']);
+ if(isset($_SESSION['user'])) {
+ $dbUser = $mysql->getUserRecordFromId($_SESSION['user']['id']);
+
+ $user = $_SESSION['user'];
+
+ $user['is_admin'] = $dbUser['is_admin'];
+
+ $twig->addGlobal('user', $user);
+ }
$res = $curl->get('https://crss.blurryface.xyz/api/v1/players');
@@ -45,6 +52,7 @@
$twig->addGlobal('playerCount', $json);
$twig->addGlobal('nations', $nations);
+ $twig->addGlobal('dc_uri', 'https://discord.com/api/oauth2/authorize?client_id=1144248396467683338&redirect_uri=' . urlencode($_ENV['DISCORD_REDIRECT']) . '&response_type=code&scope=identify%20guilds&state=' . urlencode($_SERVER['REQUEST_URI']));
$twig->addGlobal('reduced', isset($_GET['reduced']));
@@ -152,16 +160,45 @@
$markers = $mysql->getMarkers();
if ($user == null && $user['admin'] == 0) {
- http_response_code(404);
+ http_response_code(401);
- echo $twig->render('404.twig');
+ echo '';
} else {
echo $twig->render('admin/index.twig', array('users' => $users, 'markers' => $markers));
}
} else {
- http_response_code(404);
+ http_response_code(401);
- echo $twig->render('404.twig');
+ echo '';
+ }
+ });
+
+ $router->get('/admin/__data/page/([a-z]+)', function($page) {
+ global $twig, $mysql;
+
+ if (isset($_SESSION['user'])) {
+ $user = $mysql->getUserRecordFromId($_SESSION['user']['id']);
+
+ $users = $mysql->getUsers();
+ $markers = $mysql->getMarkers();
+
+ if ($user == null && $user['admin'] == 0) {
+ http_response_code(401);
+
+ echo '';
+ } else {
+ try {
+ echo $twig->render('admin/pages/' . urlencode($page) . '.twig', array('users' => $users, 'markers' => $markers));
+ } catch (Exception $e) {
+ http_response_code(404);
+
+ echo $twig->render('admin/pages/404.twig');
+ }
+ }
+ } else {
+ http_response_code(401);
+
+ echo '';
}
});
diff --git a/js/admin/nav.js b/js/admin/nav.js
new file mode 100644
index 0000000..9ddebc4
--- /dev/null
+++ b/js/admin/nav.js
@@ -0,0 +1,50 @@
+const pageContainer = document.querySelector('.pageContainer');
+
+window.history.pushState({}, '', '#/');
+
+window.addEventListener('hashchange', () => {
+ let uri = window.location.href.split('#')[1];
+
+ if (!window.location.href.includes('#'))
+ uri = '/admin#/'
+
+ const allActiveLinks = document.querySelectorAll('.nav a.active');
+ const allLinksWithThisUrl = document.querySelectorAll(`.nav a[href="#${uri}"]`);
+
+ allActiveLinks.forEach(activeLink => {
+ activeLink.classList.remove('active');
+ activeLink.classList.add('link-body-emphasis');
+ });
+
+ allLinksWithThisUrl.forEach(link => {
+ link.classList.add('active');
+ link.classList.remove('link-body-emphasis');
+ });
+
+ changePage(window.location.href.split('#')[1].replace('/', ''));
+});
+
+const changePage = (url) => {
+ if (!url)
+ url = 'dashboard';
+
+ pageContainer.innerHTML = ``;
+
+ pageContainer.classList.add('d-flex');
+ pageContainer.classList.add('align-items-center');
+ pageContainer.classList.add('justify-content-center');
+
+ lucide.createIcons();
+
+ fetch(`/admin/__data/page/${url}`)
+ .then(res => res.text())
+ .then(html => {
+ pageContainer.innerHTML = html;
+
+ pageContainer.classList.remove('d-flex');
+ pageContainer.classList.remove('align-items-center');
+ pageContainer.classList.remove('justify-content-center');
+
+ lucide.createIcons();
+ });
+};
\ No newline at end of file
diff --git a/template/admin/includes/foot.twig b/template/admin/includes/foot.twig
new file mode 100644
index 0000000..d1e0e0b
--- /dev/null
+++ b/template/admin/includes/foot.twig
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+