コード例 #1
0
    def modify_totp(username, password):
        """
        Update the TOTP secret
        """
        resp = Response("OK")

        if UserManager.verify_match(username, password):
            try:
                totp_secret = UserManager._reset_totp(username)

                otpauth_link = 'otpauth://totp/%s?secret=%s' % (username,
                                                                totp_secret)
                qr_code = pyqrcode.create(otpauth_link)

                template_args = {
                    'username': username,
                    'totp_secret': totp_secret,
                    'qr_blob': qr_code.png_as_base64_str(scale=5)
                }

                mako_template = LOOKUP.get_template('modify_totp.mako')
                resp.message = mako_template.render(**template_args)
            except RuntimeError:
                resp = BadRequest("Username not found")
        else:
            resp = BadRequest("Username/password mismatch")
        return resp
コード例 #2
0
    def update_password(self, newpassword, url):
        """
        Updates the password
        :param username: Username given by the user
        :param newpassword: New Password selected by the user
        """
        resp = Response("OK")
        try:
            usernm = UserManager._update_password(self.username, newpassword)

            # mako_template = LOOKUP.get_template(self.mako_template3)

        except RuntimeError:
            resp = BadRequest("Username %s not found" % self.username)
        """
        Update the TOTP secret
        """
        try:
            totp_secret = UserManager._reset_totp(self.username)

            otpauth_link = 'otpauth://totp/%s?secret=%s' % (self.username,
                                                            totp_secret)
            qr_code = pyqrcode.create(otpauth_link)

            template_args = {
                'username': self.username,
                'totp_secret': totp_secret,
                'qr_blob': qr_code.png_as_base64_str(scale=5),
                'home_url': url
            }

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