Exemplo n.º 1
0
    def post(self):

        submission_id = self.get_argument("submission_id", "")

        # Decrypt submission_id.
        try:
            submission_id = decrypt_number(submission_id)
        except ValueError:
            # We reply with Forbidden if the given ID cannot be
            # decrypted.
            logger.warning(
                "User %s tried to play a token " "on an undecryptable submission_id." % self.current_user.username
            )
            raise tornado.web.HTTPError(403)

        # Find submission and check it is of the current user.
        submission = Submission.get_from_id(submission_id, self.sql_session)
        if submission is None or submission.user != self.current_user:
            logger.warning(
                "User %s tried to play a token " "on an unexisting submission_id." % self.current_user.username
            )
            raise tornado.web.HTTPError(404)

        # Don't trust the user, check again if (s)he can really play
        # the token.
        timestamp = int(time.time())
        if self.contest.tokens_available(self.current_user.username, submission.task.name, timestamp)[0] <= 0:
            logger.warning("User %s tried to play a token " "when it shouldn't." % self.current_user.username)
            # Add "no luck" notification
            self.application.service.add_notification(
                self.current_user.username,
                timestamp,
                self._("Token request discarded"),
                self._("Your request has been discarded because you have no " "tokens available."),
            )
            self.redirect("/tasks/%s" % encrypt_number(submission.task.id))
            return

        token = Token(timestamp, submission)
        self.sql_session.add(token)
        self.sql_session.commit()

        # Inform ScoringService and eventually the ranking that the
        # token has been played.
        self.application.service.scoring_service.submission_tokened(submission_id=submission_id, timestamp=timestamp)

        logger.info("Token played by user %s on task %s." % (self.current_user.username, submission.task.name))

        # Add "All ok" notification
        self.application.service.add_notification(
            self.current_user.username,
            timestamp,
            self._("Token request received"),
            self._("Your request has been received " "and applied to the submission."),
        )

        self.redirect("/tasks/%s" % encrypt_number(submission.task.id))
Exemplo n.º 2
0
 def get_submission_id(self):
     # Only valid after self.execute()
     # Parse submission ID out of response.
     p = urlparse.urlparse(self.browser.geturl())
     try:
         submission_id = decrypt_number(p.query)
     except:
         return None
     return submission_id
Exemplo n.º 3
0
 def get_submission_id(self):
     # Only valid after self.execute()
     # Parse submission ID out of response.
     p = self.browser.geturl().split("?")[-1]
     try:
         submission_id = decrypt_number(p)
     except Exception:
         return None
     return submission_id
Exemplo n.º 4
0
 def get_submission_id(self):
     # Only valid after self.execute()
     # Parse submission ID out of response.
     p = self.browser.geturl().split("?")[-1]
     try:
         submission_id = decrypt_number(p)
     except Exception as error:
         return None
     return submission_id
Exemplo n.º 5
0
 def newfunc(self, *args, **kwargs):
     # We reply with Forbidden if the given ID cannot be decrypted.
     new_args = []
     for arg in args:
         try:
             new_args.append(decrypt_number(arg))
         except ValueError:
             logger.warning("User %s called with undecryptable argument." %
                            self.current_user.username)
             raise HTTPError(403)
     new_kwargs = {}
     for k in kwargs:
         try:
             new_kwargs[k] = decrypt_number(kwargs[k])
         except ValueError:
             logger.warning("User %s called with undecryptable argument." %
                            self.current_user.username)
             raise HTTPError(403)
     return func(self, *new_args, **new_kwargs)