summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorTeddy <[email protected]>2013-08-23 10:07:43 +0800
committerTeddy <[email protected]>2013-08-23 10:07:43 +0800
commit5c471d58e11ec21b8bee3c7e7a2fb8436952b64d (patch)
tree9cee58bebf63e15bfbba6e8a5088f705feb07153 /server
parentdd0fe5add36e910e07d5ab29b888859c1b569a0b (diff)
...
Diffstat (limited to 'server')
-rw-r--r--server/piztor_server.py18
-rw-r--r--server/ptp.rst2
2 files changed, 12 insertions, 8 deletions
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