From b4e7800fb72b36ae1ea4db6ab28421a6e66dcb9f Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Thu, 16 Jun 2011 20:01:49 -0400 Subject: [PATCH] Add an optional 'expires' argument to GetSession() to allow longer expirations --- PLC/Methods/GetSession.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/PLC/Methods/GetSession.py b/PLC/Methods/GetSession.py index 6a8ac4c..82dccbf 100644 --- a/PLC/Methods/GetSession.py +++ b/PLC/Methods/GetSession.py @@ -11,14 +11,18 @@ class GetSession(Method): """ Returns a new session key if a user or node authenticated successfully, faults otherwise. + + Default value for 'expires' is 24 hours. Otherwise, the returned + session 'expires' in the given number of seconds. """ roles = ['admin', 'pi', 'user', 'tech', 'node'] - accepts = [Auth()] + accepts = [Auth(), + Parameter(int,"expires", nullok=True)] returns = Session.fields['session_id'] - def call(self, auth): + def call(self, auth, expires=None): # Authenticated with a session key, just return it if auth.has_key('session'): return auth['session'] @@ -27,7 +31,10 @@ class GetSession(Method): if isinstance(self.caller, Person): # XXX Make this configurable - session['expires'] = int(time.time()) + (24 * 60 * 60) + if expires is None: + session['expires'] = int(time.time()) + (24 * 60 * 60) + else: + session['expires'] = int(time.time()) + int(expires) session.sync(commit = False) -- 2.43.0