Skip to content

Commit

Permalink
Filtering out registration if reg is locked
Browse files Browse the repository at this point in the history
  • Loading branch information
rsnakeactual committed Nov 10, 2024
1 parent 8d64bf4 commit 065524d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions static/js/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ let loggedoutnav = [{
"href": "/rd-forgot"
}];

async function updateNavigation(isAuthenticated, isAdmin) {
async function updateNavigation(isAuthenticated, isAdmin, regLocked) {
const dropdownMenu = document.querySelector('.dropdown-menu');
if (!dropdownMenu) return;

dropdownMenu.innerHTML = ''; // Clear existing menu items

let navItems = isAuthenticated ? loggedinnav : loggedoutnav;

// Filter out Register link if registration is locked
if (regLocked) {
navItems = navItems.filter(item => item.name !== "Register");
}

// Remove the current page's link from the dropdown
const currentFullPath = window.location.pathname + window.location.search;
navItems = navItems.filter(item => item.href !== currentFullPath);
Expand Down Expand Up @@ -76,7 +81,8 @@ async function checkAuthentication() {

const isAuthenticated = data.valid === 1;
const isAdmin = data.admin === 1;
updateNavigation(isAuthenticated, isAdmin);
const regLocked = data.reg_locked === 1;
updateNavigation(isAuthenticated, isAdmin, regLocked);

// Optional: update auth status display
let authStatusDiv = document.getElementById('auth-status');
Expand All @@ -87,7 +93,7 @@ async function checkAuthentication() {

} catch (error) {
console.error('Detailed error:', error);
updateNavigation(false, false);
updateNavigation(false, false, false);

// Optional: update auth status display
let authStatusDiv = document.getElementById('auth-status');
Expand Down

0 comments on commit 065524d

Please sign in to comment.