Showing vote thanks page, restricting vote names to pre specified ones

This commit is contained in:
MrFry 2020-04-20 14:51:49 +02:00
parent d55115f353
commit bd8e46f6c7
2 changed files with 53 additions and 4 deletions

View file

@ -40,6 +40,7 @@ const dataEditsLog = 'stats/dataEdits'
const dailyDataCountFile = 'stats/dailyDataCount'
const usersDbBackupPath = 'data/dbs/backup'
const quickVoteResultsDir = 'stats/qvote'
const quickVotes = 'stats/qvote/votes.json'
// other constants
const maxVeteranPwGetCount = 10
@ -135,13 +136,30 @@ function GetApp () {
const val = req.query.val
if (!key || !val) {
res.json({
res.render('votethank', {
results: 'error',
msg: 'no key or val query param!'
})
return
}
let votes = {}
if (utils.FileExists(quickVotes)) {
votes = utils.ReadJSON(quickVotes)
} else {
res.render('votethank', {
result: 'no such pool'
})
return
}
if (!votes.voteNames.includes(key)) {
res.render('votethank', {
result: 'no such pool'
})
return
}
const voteFile = quickVoteResultsDir + '/' + key + '.json'
const user = req.session.user
@ -165,14 +183,14 @@ function GetApp () {
voteData.users.push(user.id)
logger.Log(`Vote from #${user.id}: ${key}: ${val}`, logger.GetColor('blue'))
res.json({
res.render('votethank', {
result: 'success',
msg: 'vote added'
})
} else {
logger.Log(`#${user.id} already voted for: ${key}: ${val}`, logger.GetColor('blue'))
res.json({
result: 'success',
res.render('votethank', {
result: 'already voted',
msg: 'already voted'
})
}