view website/issues/extensions/timestamp.py @ 7133:b5b1f2830e23

Remove duplicate h1 headers from website Each page has an H1 header in the main part of the page. The class=header block also had an H1 enclosing "Roundup". This isn't useful as an H1 header. The page title includes Roundup as well so I demoted the class=header H1 to a label but styled it the same.
author John Rouillard <rouilj@ieee.org>
date Wed, 15 Feb 2023 10:36:09 -0500
parents 35ea9b1efc14
children
line wrap: on
line source

import time, struct, base64
from roundup.cgi.actions import RegisterAction
from roundup.cgi.exceptions import *

def timestamp():
    return base64.encodestring(struct.pack("i", time.time())).strip()

def unpack_timestamp(s):
    return struct.unpack("i",base64.decodestring(s))[0]

class Timestamped:
    def check(self):
        try:
            created = unpack_timestamp(self.form['opaque'].value)
        except KeyError:
            raise FormError("somebody tampered with the form")
        if time.time() - created < 4:
            raise FormError("responding to the form too quickly")
        return True

class TimestampedRegister(Timestamped, RegisterAction):
    def permission(self):
        self.check()
        RegisterAction.permission(self)

def init(instance):
    instance.registerUtil('timestamp', timestamp)
    instance.registerAction('register', TimestampedRegister)

Roundup Issue Tracker: http://roundup-tracker.org/