From 5c471d58e11ec21b8bee3c7e7a2fb8436952b64d Mon Sep 17 00:00:00 2001 From: Teddy Date: Fri, 23 Aug 2013 10:07:43 +0800 Subject: ... --- server/piztor_server.py | 18 +++++++++++------- server/ptp.rst | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'server') diff --git a/server/piztor_server.py b/server/piztor_server.py index ec6d1ae..d36df0d 100644 --- a/server/piztor_server.py +++ b/server/piztor_server.py @@ -43,10 +43,15 @@ class UserManager(DataManager): id = Column(Integer, primary_key = True) username = Column(String) password = Column(String) + token = Column(Integer) def get_user_by_token(self, token): try: - return self.piz_srv.active_sessions[token] + session = Session() + User = UserManager.User + q = session.query(User).filter(User.token == token) + entry = q.first() + return entry except: raise TokenInvalidError() @@ -77,8 +82,7 @@ class UserManager(DataManager): return struct.pack("!BlB", 0, 0, 1) else: # Succeeded print "Logged in sucessfully!" - token = entry.id - self.piz_srv.active_sessions[token] = entry + entry.token = randint(0, 2147483647) return struct.pack("!BlB", 0, token, 0) @@ -122,11 +126,12 @@ class LocationManager(DataManager): entry.lat = lat entry.lng = lng session.commit() - return struct.pack("!B", 2) - except struct.error, TokenInvalidError: + return struct.pack("!BB", 2, 0) + except TokenInvalidError: + return struct.pack("!BB", 2, 1) + except struct.error: raise ReqInvalidError() - class PiztorServer(): @@ -174,7 +179,6 @@ class PiztorServer(): self.location_mgr.location_update_handle ] Base.metadata.create_all(engine) - self.active_sessions = dict() def run(self): diff --git a/server/ptp.rst b/server/ptp.rst index dc2f672..02a862f 100644 --- a/server/ptp.rst +++ b/server/ptp.rst @@ -40,7 +40,7 @@ Piztor Transmission Protocol v0.1 STATUS: - 0x00 for success - - 0x01 for already logged in (kicked another online device) + - 0x01 for failure - Message Sending -- cgit v1.2.3-70-g09d2