Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treasure Hunt: Merge 2 #20

Merged
merged 14 commits into from
Mar 15, 2024
41 changes: 41 additions & 0 deletions assets/styles/form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,44 @@ input[type=date]{
text-decoration: underline;
font-weight: 600;
}
.loader{
width: 100px;
height: 100px;
}

.circular{
animation: rotate 2s linear infinite;
height: 100px;
position: relative;
width: 100px;
}

.path {
stroke-dasharray: 1,200;
stroke-dashoffset: 0;
stroke:var(--red);
animation:
dash 1.5s ease-in-out infinite,
;
stroke-linecap: round;
}

@keyframes rotate{
100%{
transform: rotate(360deg);
}
}
@keyframes dash{
0%{
stroke-dasharray: 1,200;
stroke-dashoffset: 0;
}
50%{
stroke-dasharray: 89,200;
stroke-dashoffset: -35;
}
100%{
stroke-dasharray: 89,200;
stroke-dashoffset: -124;
}
}
2 changes: 1 addition & 1 deletion database/Schemas/Location.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const mongoose = require('mongoose');

const locationSchema = new mongoose.Schema({
_id: { type: String, required: true },
_id: { type: Number, required: true },
name: { type: String, required: true },
pointerQuestion: [{ type: String, required: true }],
code: { type: String, required: true },
Expand Down
2 changes: 1 addition & 1 deletion database/Schemas/Team.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const teamSchema = new mongoose.Schema({
phone: { type: String, required: true }
}
],
status: { type: String, required: true },
status: { type: String, required: true, enum: ['location-code', 'riddle-question', 'riddle-timeout', 'completed'] },
questionsAttempted: { type: Number, required: true, default: 0 },
order: [
{
Expand Down
6 changes: 3 additions & 3 deletions database/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ async function updateTeamStatus (ctx) {
const team = await Team.findById(_id);
team.status = status;
if (status === 'riddle-timeout') {
team.timeout = new Date(Date.now() + 120 * 1000);
team.timeout = new Date(Date.now() + (120 + 5) * 1000);
setTimeout(async () => {
team.status = 'riddle-question';
team.timeout = null;
await team.save();
}, 120 * 1000);
} else if (status === 'location-code') {
}, (115 + 5) * 1000);
} else {
team.questionsAttempted = ctx.questionNo;
}
return await team.save();
Expand Down
4 changes: 2 additions & 2 deletions routers/base-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ router.get(['/home', '/'], (req, res) => {
return res.renderFile('info/landing.njk');
});

router.get('/information', (req, res) => {
return res.renderFile('info/information.njk');
router.get('/instructions', (req, res) => {
return res.renderFile('info/instructions.njk');
});

module.exports = {
Expand Down
125 changes: 65 additions & 60 deletions routers/live-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,102 +4,107 @@ const { body, validationResult } = require('express-validator');
const checker = require('../src/checker.js');

const teams = require('../src/samples/teams.json');
// const locations = require('../src/samples/locations.json');
const locations = require('../src/samples/locations.json');

const handlerContext = {};

const ques = 6;

router.use((req, res, next) => {
if (!req.loggedIn) return req.method === 'GET' ? res.redirect('/login') : res.status(403).send('Forbidden. Not logged in.');
return next();
});

router.use((req, res, next) => {
if (handlerContext.huntStarted || req.isAdmin) return next();
return req.method === 'GET' ? res.redirect('/') : res.status(400).send('Hunt not started');
return req.method === 'GET' ? res.redirect('/') : res.status(786).send('ALLAHU AKBAR!!!');
});

// const team = teams[1];

// const locationQuestion = {
// id: 1,
// question: 'Where is the best waifu',
// answer: 'Oregairu'
// };

// const riddleQuestion = riddleQuestions[0];

// const locationCode = 'ABC123';

router.get('/', async (req, res) => {
if (req.isAdmin) {
const teamList = await dbh.getTeams();
teamList.sort((t1, t2) => {
return -(t1._id < t2._id);
});
return res.renderFile('admin/team-list.njk', {
teams: teamList
});
} else {
// if (!handlerContext.quizStarted) return res.redirect('/');
return res.renderFile('live/interface.njk', {
team: req.team,
started: handlerContext.huntStarted
started: true
});
// return res.renderFile('live/interface.njk');
}
});

router.post('/get-data', async (req, res) => {
// combine the bottom 3 into one route
router.post('/get-data', (req, res) => {
const teamID = req.body.teamID;
if (teamID !== req.team._id) return res.status(500).send('WHy you hax');
const locations = await dbh.getLocations();
return res.status(200).send(JSON.stringify({
team: req.team,
locations: req.team.order.map((o) => locations.find((l) => l._id === o.location))
}));
return res.status(200).send(req.team);
});

router.post('/get-location-question', (req, res) => {
const attempted = req.team.questionsAttempted;
if (attempted >= ques) return res.status(418).send('Completed');
return res.send(
req.team.order.map((o) =>
handlerContext.locations.find((l) => l._id === o.location)
)[attempted].pointerQuestion[req.team.order[attempted].pointer]
);
});

router.post('/get-riddle-question', (req, res) => {
const attempted = req.team.questionsAttempted;
if (attempted >= ques) return res.status(418).send('Completed');
const location = req.team.order.map((o) => handlerContext.locations.find((l) => l._id === o.location))[attempted];
return res.send({
question: location.questions[req.team.order[attempted].question].question,
keywords: location.keywords
});
});

router.post('/get-attempted', (req, res) => {
const teamID = req.body.teamID;
if (teamID !== req.team._id) return res.status(500).send('WHy you hax');
return res.status(200).send(req.team.questionsAttempted);
});
router.post('/get-state', (req, res) => {
const teamID = req.body.teamID;
if (teamID !== req.team._id) return res.status(500).send('WHy you hax');
return res.status(200).send(req.team.status);
});
router.post('/get-timeout', async (req, res) => {
if (req.team.status === 'riddle-timeout') {
return res.status(200).send(req.team.timeout);
router.post('/submit', async (req, res) => {
const attempted = req.team.questionsAttempted;
if (req.body.questionNo !== attempted) return res.status(420).send('Koi bkl hi hoga');
if (req.body.state !== req.team.status) return res.status(420).send('Koi bkl hi hoga');
if (req.body.state === 'riddle-question') {
if (attempted + 1 >= ques) {
await dbh.updateTeamStatus({ _id: req.team._id, status: 'completed', questionNo: 6 });
return res.status(418).send('Completed');
}
}
if (req.body.state === 'riddle-question') {
if (
req.team.order.map((o) =>
handlerContext.locations.find((l) => l._id === o.location)
)[attempted].questions[req.team.order[attempted].question].answer === parseInt(req.body.answer)
) {
await dbh.updateTeamStatus({ _id: req.team._id, status: 'location-code', questionNo: req.body.questionNo + 1 });
return res.status(200).send('correct answer');
}
await dbh.updateTeamStatus({ _id: req.team._id, status: 'riddle-timeout', questionNo: req.body.questionNo });
return res.status(469).send('wrong answer');
} else if (req.body.state === 'location-code') {
if (
req.team.order.map((o) =>
handlerContext.locations.find((l) => l._id === o.location)
)[attempted].code === req.body.answer
) {
await dbh.updateTeamStatus({ _id: req.team._id, status: 'riddle-question', questionNo: req.body.questionNo });
return res.status(200).send('correct answer');
}
return res.status(469).send('wrong answer');
}
return res.status(400).send(false);
});

router.post('/update-status', async (req, res) => {
// if (req.body.questionNo !== req.team.questionsAttempted) return;
await dbh.updateTeamStatus({ _id: req.team._id, status: req.body.status, questionNo: req.body.questionNo });
return res.status(200).send('Updated Successfully');
});
router.post('/update-attempted', async (req, res) => {
await dbh.updateTeamStatus({ _id: req.team._id, status: req.body.status, questionNo: req.body.questionNo });
return res.status(200).send('Updated Successfully');
});

// router.patch('/location-code', async (req, res) => {
// const teamID = parseInt(req.body.id);
// const location = req.body.locationcode;
// // console.log(teamID);
// // console.log(location);
// // FIND TEAM BY ID IN LOCAL STORAGE
// // MARK TEAM AS COMPLETED FOR LOCATION BY FINDING TEAM BY ID AND ADDING LOCATION TO COMPLETED LOCATIONS LIST
// if (location === locationCode) {
// return res.send('correct');
// } else {
// return res.status(400).send('incorrect location');
// }
// });

router.post('/start-hunt', (req, res) => {
router.post('/start-hunt', async (req, res) => {
if (!req.isAdmin) return res.status(403).send('Forbidden: Admin permissions not detected.');
handlerContext.huntStarted = true;
handlerContext.teams = await dbh.getTeams();
handlerContext.locations = await dbh.getLocations();
return res.send('Hunt Started');
});

Expand Down
23 changes: 7 additions & 16 deletions templates/_base.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set navlinks = [
{ name: 'Information', href: 'information' },
{ name: 'Quiz Portal', href: 'live' }
{ name: 'Instructions', href: 'instructions' },
{ name: 'Treasure Hunt', href: 'live' }
] %}
{# array elements: { name, href } #}

Expand Down Expand Up @@ -62,14 +62,8 @@
<div style="float:right;" id="dropdown">
{% if not loggedIn %}
<a href="/login" class="dropbtn {{ 'active-page' if thispage === 'login' }}" target="_self">Login</a>
<div class="dropdown-content">
<a href="/signup" class="{% if 'register' === thispage %}active-page {% endif %}{% if mongoless %}disabled {% endif %}" target="_self"> Register </a>
</div>
{% else %}
<a href="/profile" class="dropbtn {{ 'active-page' if thispage === 'profile' }}" target="_self" disabled>Profile</a>
<div class="dropdown-content">
<a href="/logout" class="{% if 'logout' === thispage %}active-page {% endif %}{% if mongoless %}disabled {% endif %}" target="_self">Logout</a>
</div>
<a href="/logout" class="{% if 'logout' === thispage %}active-page {% endif %}{% if mongoless %}disabled {% endif %}" target="_self">Logout</a>
{% endif %}
</div>
</ul>
Expand All @@ -80,19 +74,16 @@
<hr id="top-line"/>
{% for link in navlinks %}
<a href="{{ '/' if loop.index0 }}{{ link.href }}" target="_self"><div class="lettuce{% if link.href == thispage %} active-page {% endif %}" >{{ link.name }}</div></a>
{% if not loop.last %}<hr class="minor"/>{% endif %}
<hr class="minor"/>
{% endfor %}

{# <a href="/about" target="_self"><div class="lettuce{% if 'about' == thispage %} active-page {% endif %}" id="most-bottom">Our Society</div></a>
<hr class="minor lower-border"/>
<a href="/members" target="_self"><div class="lettuce{% if 'members' == thispage %} active-page{% endif %}" id="almost-bottom">Our Members</div></a> #}
{% if loggedIn %}
<a href="/profile" target="_self"><div class="lettuce{% if 'profile' == thispage %} active-page{% endif %}{% if mongoless %} disabled{% endif %}" id="almost-bottom">Profile</div></a>
<hr class="minor lower-border">
<a href="/logout" target="_self"><div class="lettuce{% if 'logout' == thispage %} active-page{% endif %}{% if mongoless %} disabled{% endif %}" id="most-bottom"> Logout </div></a>
<a href="/logout" target="_self"><div class="lettuce{% if 'logout' == thispage %} active-page{% endif %}{% if mongoless %} disabled{% endif %}"> Logout </div></a>
{% else %}
<a href="/login" target="_self"><div class="lettuce{% if 'login' == thispage %} active-page{% endif %}{% if mongoless %} disabled{% endif %}" id="almost-bottom"> Login </div></a>
<hr class="minor lower-border">
<a href="/signup" target="_self"><div class="lettuce{% if 'register' == thispage %} active-page{% endif %}{% if mongoless %} disabled{% endif %}" id="most-bottom"> Register </div></a>
<a href="/login" target="_self"><div class="lettuce{% if 'login' == thispage %} active-page{% endif %}{% if mongoless %} disabled{% endif %}"> Login </div></a>
{% endif %}
<hr class="border-bottom"/>
</div>
Expand Down
3 changes: 1 addition & 2 deletions templates/admin/team-edit.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
{% block pagecontent %}
{% call forms.form() %}
{{ forms.heading('h1','Edit Team') }}
<label>Team ID:</label><br>
{{ forms.field('id','ID', team._id)}}
<label>Team ID: {{ team._id }}</label><br>
<label>Team Name:</label><br>
{{ forms.field('teamName','Name', team.name)}}
<label>Members:</label><br>
Expand Down
5 changes: 2 additions & 3 deletions templates/auth/login.njk
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
{% block pagecontent %}
{% call forms.form() %}
{{ forms.heading('h1','Login') }}
{{ forms.link('registerlink', "New to our site? ", 'Register Now!', link='/signup' )}}
{{ forms.field('username','Username')}}
{{ forms.field('password','Password',type='password')}}
{{ forms.field('username','Team ID')}}
{{ forms.field('password','Passcode',type='password')}}
{{ forms.button('submit', 'Login', 'login') }}
{% endcall %}
{% endblock %}
Expand Down
53 changes: 0 additions & 53 deletions templates/info/information.njk

This file was deleted.

Loading
Loading