From 5ea15efe502f1e98486197bd38549c91406f0c67 Mon Sep 17 00:00:00 2001 From: singharaj usai Date: Sun, 13 Oct 2024 21:25:03 -0400 Subject: [PATCH] admin dashboard button link --- client/html/components/navbar.html | 6 ++++++ client/html/pages/admin/dashboard.html | 3 ++- client/js/admin/init.js | 19 ++++++++++++++++--- client/js/auth/auth.js | 13 +++++++++++++ server/functions/api/routes/auth.js | 6 ++++++ server/functions/api/routes/user.js | 1 + 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/client/html/components/navbar.html b/client/html/components/navbar.html index 1ecd581..95d5dba 100644 --- a/client/html/components/navbar.html +++ b/client/html/components/navbar.html @@ -140,6 +140,9 @@
  • Create
  • + diff --git a/client/html/pages/admin/dashboard.html b/client/html/pages/admin/dashboard.html index 3009fdb..7155297 100644 --- a/client/html/pages/admin/dashboard.html +++ b/client/html/pages/admin/dashboard.html @@ -47,7 +47,8 @@ diff --git a/client/js/admin/init.js b/client/js/admin/init.js index 387f50c..fd93705 100644 --- a/client/js/admin/init.js +++ b/client/js/admin/init.js @@ -57,7 +57,20 @@ function loadOverview() {

    Select a section from the sidebar or click on a panel below to manage different aspects of the website.

    -
    +
    +
    +
    +

    Assets

    +
    +
    +

    View and manage assets.

    + +
    +
    +
    +

    Forum Posts

    @@ -70,7 +83,7 @@ function loadOverview() {
    -
    +

    Users

    @@ -83,7 +96,7 @@ function loadOverview() {
    -
    +

    Games

    diff --git a/client/js/auth/auth.js b/client/js/auth/auth.js index 1ef711b..67f55ed 100644 --- a/client/js/auth/auth.js +++ b/client/js/auth/auth.js @@ -294,6 +294,17 @@ const App = { html: true, container: 'body', }); + + if (response.isAdmin) { + $('.admin-dashboard-link').show(); + } else { + $('.admin-dashboard-link').hide(); + } + + + // Show mobile user submenu for all authenticated users + $('#mobile-user-submenu').show(); + }, error: (xhr, status, error) => { console.error('Error fetching user info:', error); @@ -306,6 +317,8 @@ const App = { Register `); $('#user-submenu').hide(); + $('#mobile-user-submenu').hide(); + $('.admin-dashboard-link').hide(); } if (typeof updateAnnouncementPosition === 'function') { updateAnnouncementPosition(); diff --git a/server/functions/api/routes/auth.js b/server/functions/api/routes/auth.js index d88cc4e..97fee06 100644 --- a/server/functions/api/routes/auth.js +++ b/server/functions/api/routes/auth.js @@ -500,6 +500,12 @@ router.post('/login', flexibleCsrfProtection, authLimiter, async (req, res) => { }); } + if (user.isBanned) { + return res.status(403).json({ + message: 'Your account is banned. Please contact the administrator for more information.', + }); + } + const isValidPassword = await bcrypt.compare(password, user.password); if (!isValidPassword) { user.loginAttempts += 1; diff --git a/server/functions/api/routes/user.js b/server/functions/api/routes/user.js index 21042dd..bd10e84 100644 --- a/server/functions/api/routes/user.js +++ b/server/functions/api/routes/user.js @@ -99,6 +99,7 @@ router.get('/user-info', authenticateToken, async (req, res) => { username: user.username, currency: user.currency, lastCurrencyClaimDate: user.lastCurrencyClaimDate, + isAdmin: user.isAdmin, }); } catch (error) { console.error('Error fetching user info:', error);