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