Exemplo n.º 1
0
    def show_question(self, url):
        """
        Returns the secret question for the given user
        :param username: Username given by the user
        :return:
        """
        resp = Response("OK")
        try:
            question_str = UserManager._read_lostqstn(self.username)
            # question_str = 'Have you lost your marbles'

            template_args = {
                'title': 'Password Recovery',
                'question': 'Question: ',
                'question_str': question_str,
                'answer': 'Answer:',
                'submit_text': 'Submit',
                'wrong_answer': 0,
                'url': url
            }
            mako_template = LOOKUP.get_template(self.mako_template2)
            resp.message = mako_template.render(**template_args)

        except RuntimeError:
            resp = BadRequest("Username not found")

        return resp
Exemplo n.º 2
0
    def check_answer(self, answer, url):
        """
        Checks if the answer is correct
        :param username: Username given by the user
        :param answer: Answer to the question
        :return:
        """
        resp = Response("Username not found")
        try:
            # question_str = UserManager.verify_lostpwd(self.username,answer)

            if UserManager.verify_lostpwd(self.username, answer):

                template_args = {
                    'title': 'Password Recovery',
                    'password_title': 'New password: '******'newpassword_title': 'Confirm new password: '******'submit_text': 'Submit',
                    'url': url
                }

                mako_template = LOOKUP.get_template(self.mako_template3)
                resp.message = mako_template.render(**template_args)
            else:
                question_str = UserManager._read_lostqstn(self.username)
                template_args = {
                    'title': 'Password Recovery',
                    'question': 'Question: ',
                    'question_str': question_str,
                    'answer': 'Answer:',
                    'submit_text': 'Submit',
                    'wrong_answer': 1,
                    'url': url
                }

                mako_template = LOOKUP.get_template(self.mako_template2)
                resp.message = mako_template.render(**template_args)
        except RuntimeError:
            resp = BadRequest("Username not found")
        return resp