felicity-buzz-2k16 / quiz-portal-backend

The generic quiz portal's backend
ISC License
0 stars 7 forks source link

Something's really wrong. They'll easily win. #1

Closed kartikeypant closed 8 years ago

kartikeypant commented 8 years ago

If you see, a person can easily win just by giving the correct answer to the first question multiple times. Aren't we missing something?

There must be some problem in this part of the code.

router.post('/check/:qno(\\d+)?', middleware.isAuthenticated, (req, res) => {
  var { qno } = req.params;
  const { answer } = req.body;
  const { lastQuestionAllowed } = req.user;
  if (!qno) qno = lastQuestionAllowed;
  if (qno > lastQuestionAllowed) {res.sendStatus(403); return false;}
  models.Question.findOne({where : { qno }})
    .then(question => {
      if (question) {
        if (question.answer == answer) req.user.update({lastQuestionAllowed: lastQuestionAllowed + 1});
        res.send({result: question.answer == answer});
      } else res.sendStatus(400);
    })
})

Someone please fix it.

yash-iiith commented 8 years ago

if the qno is less than lastquestionallowed and the person answers it correctly then also lastquestionallowed is incremented so in the 2nd if statement if "qno > lastquestionallowed" is replaced by "qno!=lastquestionallowed" it may solve the issue.

kartikeypant commented 8 years ago

You can't show an error message for giving answer to a question which the person has already solved. So, you need to give the condition somewhere else.

meghprkh commented 8 years ago

You are on track! ☺

But if you replace that statement then if I try to answer a previous question I would get a 403. Not very acceptable right. I should be allowed to answer a previous question. Instead try to put the condition near to where we are actually incrementing lastQuestionAllowed

Regards, Megh Parikh On 02-Jul-2016 16:38, "yash-iiith" notifications@github.com wrote:

if the qno is less than lastquestionallowed and the person answers it correctly then also lastquestionallowed is incremented so in the 2nd if statement if "qno > lastquestionallowed" is replaced by "qno!=lastquestionallowed" it may solve the issue.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/felicity-buzz-2k16/quiz-portal-backend/issues/1#issuecomment-230096597, or mute the thread https://github.com/notifications/unsubscribe/AFs91a2qCJ737z37XmiHhI-SbwbyKYI2ks5qRka8gaJpZM4JC3PY .

yash-iiith commented 8 years ago

if (question.answer == answer) req.user.update({lastQuestionAllowed: lastQuestionAllowed + 1}); in this if condition if we && qno==lastquestionallowed then it will be fine i guess

kartikeypant commented 8 years ago

Yes, you're right!

meghprkh commented 8 years ago

Yes. Great. Would be awesome if you could fork this repo and commit. Then file a PR

Regards, Megh Parikh On 02-Jul-2016 16:50, "yash-iiith" notifications@github.com wrote:

if (question.answer == answer) req.user.update({lastQuestionAllowed: lastQuestionAllowed + 1}); in this if condition if we && qno==lastquestionallowed then it will be fine i guess

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/felicity-buzz-2k16/quiz-portal-backend/issues/1#issuecomment-230097043, or mute the thread https://github.com/notifications/unsubscribe/AFs91RN40nD6tGkBxhtIrRUONKXvR1FSks5qRkl8gaJpZM4JC3PY .

meghprkh commented 8 years ago

@kartikey You win again :p

Regards, Megh Parikh On 02-Jul-2016 16:52, "Megh Parikh" meghprkh@gmail.com wrote:

Yes. Great. Would be awesome if you could fork this repo and commit. Then file a PR

Regards, Megh Parikh On 02-Jul-2016 16:50, "yash-iiith" notifications@github.com wrote:

if (question.answer == answer) req.user.update({lastQuestionAllowed: lastQuestionAllowed + 1}); in this if condition if we && qno==lastquestionallowed then it will be fine i guess

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/felicity-buzz-2k16/quiz-portal-backend/issues/1#issuecomment-230097043, or mute the thread https://github.com/notifications/unsubscribe/AFs91RN40nD6tGkBxhtIrRUONKXvR1FSks5qRkl8gaJpZM4JC3PY .

kartikeypant commented 8 years ago

@meghprkh Hahaha.. xD

meghprkh commented 8 years ago

@yash-iiith Thanks :+1: