comparison website/issues/extensions/timestamp.py @ 4024:c2d0d3e9099d website

svn repository setup
author Stefan Seefeld <stefan@users.sourceforge.net>
date Fri, 06 Feb 2009 13:16:31 +0000
parents
children 35ea9b1efc14
comparison
equal deleted inserted replaced
4023:86c38b5aed66 4024:c2d0d3e9099d
1 import time, struct, base64
2 from roundup.cgi.actions import RegisterAction
3 from roundup.cgi.exceptions import *
4
5 def timestamp():
6 return base64.encodestring(struct.pack("i", time.time())).strip()
7
8 def unpack_timestamp(s):
9 return struct.unpack("i",base64.decodestring(s))[0]
10
11 class Timestamped:
12 def check(self):
13 try:
14 created = unpack_timestamp(self.form['opaque'].value)
15 except KeyError:
16 raise FormError, "somebody tampered with the form"
17 if time.time() - created < 4:
18 raise FormError, "responding to the form too quickly"
19 return True
20
21 class TimestampedRegister(Timestamped, RegisterAction):
22 def permission(self):
23 self.check()
24 RegisterAction.permission(self)
25
26 def init(instance):
27 instance.registerUtil('timestamp', timestamp)
28 instance.registerAction('register', TimestampedRegister)

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