def awake(self, trans): SitePage.awake(self, trans) session = trans.session() request = trans.request() app = trans.application() session.values().clear() request.setURLPath("/") app.forward(trans, 'Main') return
def htBodyArgs(self): return SitePage.htBodyArgs(self) + \ ' onload="document.loginform.username.focus();"' % locals()
def __init__(self): SitePage.__init__(self) Configurable.__init__(self)
def awake(self, trans): SitePage.awake(self, trans) # awaken our superclass if self.setting('RequireLogin'): # Handle four cases: login attempt, logout, already logged in, and not already logged in. session = trans.session() request = trans.request() app = trans.application() # Are they logging out? if request.hasField('logout'): # They are logging out. Clear all session variables: session.values().clear() request.setField('extra', 'You have been logged out.') request.setField('action', request.urlPath().split('/')[-1]) app.forward(trans, 'LoginPage') # Is the session expired? elif request.isSessionExpired(): # Login page with a "logged out" message. session.values().clear() request.setField('extra', 'Your session has expired.') request.setURLPath("/") request.setField('action', "") app.forward(trans, 'LoginPage') # Are they already logged in? elif self.getLoggedInUser(): return # Are they logging in? elif request.hasField('login') \ and request.hasField('username') \ and request.hasField('password'): # They are logging in. Get login id and clear session: loginid = session.value('loginid', None) session.values().clear() # Get request fields: username = request.field('username') password = request.field('password') # Check if they can successfully log in. # The loginid must match what was previously sent. if request.field('loginid', 'nologin') == loginid \ and self.loginUser(username, password): # Successful login. # Clear out the login parameters: request.setField('newLogin',1) request.delField('username') request.delField('password') request.delField('login') request.delField('loginid') else: # Failed login attempt; have them try again: request.setField('extra', 'Login failed. Please try again.') request.setField('action', request.urlPath().split('/')[-1]) app.forward(trans, 'LoginPage') else: #Ignore favicon.ico request if request.urlPath().find("favicon.ico") != -1: return # They need to log in. session.values().clear() # Send them to the login page: request.setURLPath("/") request.setField('action', "") app.forward(trans, 'LoginPage') else: # No login is required. session = self.session() request = self.request() # Are they logging out? if request.hasField('logout'): # They are logging out. Clear all session variables. session.values().clear() # Write the page: SitePage.writeHTML(self)
def respond(self, trans): # If the user is already logged in, then process this request normally. # Otherwise, do nothing. # All of the login logic has already happened in awake(). if self.getLoggedInUser(): SitePage.respond(self, trans)