summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorTeddy <[email protected]>2013-08-30 22:47:52 +0800
committerTeddy <[email protected]>2013-08-30 22:47:52 +0800
commit3054e381a1d384dee4206bfe5646f057bf82446e (patch)
treeb7f4e03c178bc33e092f4e4f483a6661893b37b9 /server
parent04cd785f24d779996df8672938372467af6c9a82 (diff)
...
Diffstat (limited to 'server')
-rw-r--r--server/piztor/import.py11
-rw-r--r--server/piztor/model.py4
-rw-r--r--server/piztor/ptp.rst7
-rw-r--r--server/piztor/server.py12
4 files changed, 27 insertions, 7 deletions
diff --git a/server/piztor/import.py b/server/piztor/import.py
index b756708..7646afc 100644
--- a/server/piztor/import.py
+++ b/server/piztor/import.py
@@ -5,13 +5,15 @@ from model import *
path = "root:helloworld@localhost/piztor"
class UserData:
- def __init__(self, username, nickname, password, comp_no, sec_no, sex, sub):
+ def __init__(self, username, nickname, password,
+ comp_no, sec_no, sex, perm, sub):
self.username = username
self.nickname = nickname
self.password = password
self.comp_no = int(comp_no)
self.sec_no = int(sec_no)
self.sex = int(sex)
+ self.perm = perm
self.sub = sub
def create_database():
@@ -38,7 +40,8 @@ def import_user_data(data):
nickname = user.nickname,
sex = user.sex,
comp_no = user.comp_no,
- sec_no = user.sec_no)
+ sec_no = user.sec_no,
+ perm = user.perm)
for cn, sn in user.sub:
print cn, sn
@@ -72,7 +75,9 @@ if __name__ == '__main__':
password = line[2],
comp_no = line[3],
sec_no = line[4],
- sex = line[5], sub = sub))
+ sex = line[5],
+ perm = line[6],
+ sub = sub))
create_database()
diff --git a/server/piztor/model.py b/server/piztor/model.py
index 03c0192..dd44fa2 100644
--- a/server/piztor/model.py
+++ b/server/piztor/model.py
@@ -53,6 +53,7 @@ class UserModel(Base):
comp_id = Column(Integer)
sec_id = Column(Integer)
+ perm = Column(TINYINT, nullable = False)
sub = relationship("GroupInfo",
secondary = group_sub,
backref = "subscribers")
@@ -64,13 +65,14 @@ class UserModel(Base):
def to_gid(self, comp_no, sec_no):
return comp_no * 256 + sec_no
- def __init__(self, username, nickname, sex, comp_no, sec_no):
+ def __init__(self, username, nickname, sex, comp_no, sec_no, perm):
self.username = username
self.nickname = nickname
self.sex = sex
self.comp_id = UserModel.to_gid(comp_no, 0xff)
self.sec_id = UserModel.to_gid(comp_no, sec_no)
self.sub = list()
+ self.perm = perm
class LocationInfo(Base):
diff --git a/server/piztor/ptp.rst b/server/piztor/ptp.rst
index 05fb17f..6d8ff30 100644
--- a/server/piztor/ptp.rst
+++ b/server/piztor/ptp.rst
@@ -81,6 +81,7 @@ Piztor Transmission Protocol v2.0a
:``0x05``: gid (value is a 2-byte ``GROUP_ID``)
:``0x06``: latitude (value is a 8-byte ``double`` )
:``0x07``: longtitude( value is a 8-byte ``double`` )
+ :``0x08``: level ( value is a 1-byte ``uchar`` )
- ``SUB_LIST`` :
@@ -248,6 +249,12 @@ Piztor Transmission Protocol v2.0a
| STATUS |
+--------+
+ ``STATUS`` :
+
+ - ``0x00`` for success
+ - ``0x01`` for invalid token
+ - ``0x02`` for insufficient level
+
- Push Notification
- General Request
diff --git a/server/piztor/server.py b/server/piztor/server.py
index dab0ccb..78a15b6 100644
--- a/server/piztor/server.py
+++ b/server/piztor/server.py
@@ -27,6 +27,10 @@ logger = logging.getLogger('piztor_server')
logger.setLevel(logging.INFO)
engine = create_engine('mysql://' + db_path, echo = False, pool_size = 1024)
+class _PermCode:
+ normal = 0x00
+ sectoin = 0x01
+ company = 0x02
class _SectionSize:
LENGTH = 4
@@ -596,9 +600,9 @@ class SetMarkerHandler(RequestHandler):
if username is None:
raise struct.error
except struct.error:
- raise BadReqError("Send text mesg: Malformed request body")
+ raise BadReqError("Set marker: Malformed request body")
- logger.info("Trying to send text mesg with "
+ logger.info("Trying to set marker with "
"(token = {0}, username = {1})"\
.format(get_hex(token), username))
@@ -610,8 +614,10 @@ class SetMarkerHandler(RequestHandler):
pt = RequestHandler.push_tunnels
u = uauth.user
- ulist = self.session.query(UserModel) \
+ if u.perm == _PermCode.section:
+ ulist = self.session.query(UserModel) \
.filter(UserModel.sec_id == u.sec_id).all()
+ else if u.perm == _PermCode.section:
for user in ulist:
uid = user.id