-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecureCountVisits.py
More file actions
28 lines (25 loc) · 1.42 KB
/
Copy pathSecureCountVisits.py
File metadata and controls
28 lines (25 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from SecurePage import SecurePage
class SecureCountVisits(SecurePage):
"""Secured version of counting visits example."""
def writeContent(self):
count = self.session().value('secure_count', 0) + 1
self.session().setValue('secure_count', count)
plural = count > 1 and 's' or ''
self.writeln('<h3>Counting Visits on a Secured Page</h3>')
if self.request().isSessionExpired():
self.writeln('<p>Your session has expired.</p>')
self.writeln("<p>You've been here"
' <strong style="background-color:yellow"> %d </strong>'
' time%s.</p>' % (count, plural))
self.writeln('<p>This page records your visits using a session object.'
' Every time you <a href="javascript:location.reload()">reload</a> or'
' <a href="SecureCountVisits">revisit</a> this page, the counter will increase.'
' If you close your browser, then your session will end and you'
' will see the counter go back to 1 on your next visit.</p>')
self.writeln('<p>Try hitting <a href="javascript:location.reload()">'
'reload</a> now.</p>')
user = self.loggedInUser()
if user:
self.writeln('<p>Authenticated user is <strong>%s</strong>.</p>' % user)
self.writeln('<p><a href="SecureCountVisits">Revisit this page</a> | '
'<a href="SecureCountVisits?logout=1">Logout</a></p>')