diff --git a/src/routes/hunts.js b/src/routes/hunts.js index e9deecc..21c04c5 100644 --- a/src/routes/hunts.js +++ b/src/routes/hunts.js @@ -158,33 +158,40 @@ router.post('/player/:username/display-name', requireAuth, (req, res) => { }); // ─── Apply to become organizer ──────────────────────────── -router.post('/player/:username/apply-organizer', requireAuth, (req, res) => { - const user = Users.findByUsername(req.params.username); - if (!user || user.id !== req.session.userId) { - return res.status(403).render('error', { title: 'Forbidden', message: 'You can only submit your own application.' }); +router.get('/apply-organizer', requireAuth, (req, res) => { + const user = Users.findById(req.session.userId); + if (user.is_organizer || user.is_admin) { + req.session.flash = { type: 'info', message: 'You already have organizer access.' }; + return res.redirect(`/player/${user.username}`); } + const pendingApplication = OrganizerApplications.findByUser(user.id); + res.render('apply-organizer', { title: 'Apply to Become an Organizer', pendingApplication }); +}); + +router.post('/apply-organizer', requireAuth, (req, res) => { + const user = Users.findById(req.session.userId); if (user.is_organizer || user.is_admin) { req.session.flash = { type: 'info', message: 'You already have organizer access.' }; return res.redirect(`/player/${user.username}`); } if (OrganizerApplications.findByUser(user.id)) { req.session.flash = { type: 'info', message: 'You already have a pending application.' }; - return res.redirect(`/player/${user.username}`); + return res.redirect('/apply-organizer'); } const reason = (req.body.reason || '').trim(); if (!reason || reason.length < 10) { req.session.flash = { type: 'danger', message: 'Please provide a reason (at least 10 characters).' }; - return res.redirect(`/player/${user.username}`); + return res.redirect('/apply-organizer'); } if (reason.length > 1000) { req.session.flash = { type: 'danger', message: 'Reason is too long (max 1000 characters).' }; - return res.redirect(`/player/${user.username}`); + return res.redirect('/apply-organizer'); } OrganizerApplications.submit(user.id, reason); req.session.flash = { type: 'success', message: 'Your organizer application has been submitted!' }; - res.redirect(`/player/${user.username}`); + res.redirect('/apply-organizer'); }); // ─── Delete own account ─────────────────────────────────── diff --git a/src/views/about.ejs b/src/views/about.ejs index 26bed2c..d92975b 100644 --- a/src/views/about.ejs +++ b/src/views/about.ejs @@ -67,6 +67,7 @@
Interested? Apply to become an organizer.
Organizers can create treasure hunts, generate QR code cards, set start dates and expiry windows, and monitor their hunt activity and leaderboards.
+If you'd like to run your own hunts, fill out the form below. An admin will review your application.
+Your application is pending review. Hang tight!
+<%= pendingApplication.reason %>
+Your application is pending review. Hang tight!
-<%= pendingApplication.reason %>
<% } else { %> -Organizers can create hunts, generate QR codes, and manage their own events. Tell us why you'd like to become one!
- +Want to create your own treasure hunts?
+ <% } %> + <%= (typeof pendingApplication !== 'undefined' && pendingApplication) ? 'View Application' : 'Apply Now' %> +