from ExamplePage import ExamplePage from MiscUtils.Funcs import uniqueId class LoginPage(ExamplePage): """A log-in screen for the example pages.""" def title(self): return 'Log In' def htBodyArgs(self): return ExamplePage.htBodyArgs(self) + \ ' onload="document.loginform.username.focus();"' % locals() def writeContent(self): self.writeln('
' '

 

') request = self.request() extra = request.field('extra', None) if not extra and request.isSessionExpired() and not request.hasField('logout'): extra = 'You have been automatically logged out due to inactivity.' if extra: self.writeln('

%s

' % self.htmlEncode(extra)) if self.session().hasValue('loginid'): loginid = self.session().value('loginid') else: # Create a "unique" login id and put it in the form as well as in the session. # Login will only be allowed if they match. loginid = uniqueId(self) self.session().setValue('loginid', loginid) action = request.field('action', '') if action: action = ' action="%s"' % action self.writeln('''

Please log in to view the example. The username and password is alice or bob.

''' % (action, loginid)) # Forward any passed in values to the user's intended page after successful login, # except for the special values used by the login mechanism itself for name, value in request.fields().items(): if name not in ('login', 'loginid', 'username', 'password', 'extra', 'logout'): if type(value) != type([]): value = [value] for v in value: self.writeln('''''' % (self.htmlEncode(name), self.htmlEncode(v))) self.writeln('
\n

 

')