4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Auth import Auth
7 from PLC.Sessions import Session, Sessions
8 from PLC.Nodes import Node, Nodes
9 from PLC.Persons import Person, Persons
11 class GetSession(Method):
13 Returns a new session key if a user or node authenticated
14 successfully, faults otherwise.
17 roles = ['admin', 'pi', 'user', 'tech', 'node']
19 returns = Session.fields['session_id']
23 # Authenticated with a session key, just return it
24 if auth.has_key('session'):
25 return auth['session']
27 session = Session(self.api)
29 if isinstance(self.caller, Person):
30 # XXX Make this configurable
31 session['expires'] = int(time.time()) + (24 * 60 * 60)
33 session.sync(commit = False)
35 if isinstance(self.caller, Node):
36 session.add_node(self.caller, commit = True)
37 elif isinstance(self.caller, Person):
38 session.add_person(self.caller, commit = True)
40 return session['session_id']