--- /dev/null
+import time
+
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Auth import SessionAuth
+from PLC.Sessions import Session, Sessions
+
+class DeleteSession(Method):
+ """
+ Invalidates the current session.
+
+ Returns 1 if successful.
+ """
+
+ roles = ['admin', 'pi', 'user', 'tech', 'node']
+ accepts = [SessionAuth()]
+ returns = Parameter(int, '1 if successful')
+
+ def call(self, auth):
+ assert auth.has_key('session')
+
+ sessions = Sessions(self.api, [auth['session']]).values()
+ if not sessions:
+ raise PLCAPIError, "No such session"
+ session = sessions[0]
+
+ session.delete()
+
+ return 1
--- /dev/null
+import time
+
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Auth import Auth
+from PLC.Sessions import Session, Sessions
+from PLC.Nodes import Node, Nodes
+from PLC.Persons import Person, Persons
+
+class GetSession(Method):
+ """
+ Returns a new session key if a user or node authenticated
+ successfully, faults otherwise.
+ """
+
+ roles = ['admin', 'pi', 'user', 'tech', 'node']
+ accepts = [Auth()]
+ returns = Session.fields['session_id']
+
+ def call(self, auth):
+ # Authenticated with a session key, just return it
+ if auth.has_key('session'):
+ return auth['session']
+
+ session = Session(self.api)
+
+ if isinstance(self.caller, Person):
+ # XXX Make this configurable
+ session['expires'] = int(time.time()) + (24 * 60 * 60)
+
+ session.sync(commit = False)
+
+ if isinstance(self.caller, Node):
+ session.add_node(self.caller, commit = True)
+ elif isinstance(self.caller, Person):
+ session.add_person(self.caller, commit = True)
+
+ return session['session_id']