From 36b66d60fe48cfeded2b3419baa8310353bf03fd Mon Sep 17 00:00:00 2001 From: Teddy Date: Mon, 26 Aug 2013 11:47:29 +0800 Subject: removed redundant code --- server/piztor/server.py | 68 +++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/server/piztor/server.py b/server/piztor/server.py index 725fc5b..5d2382d 100644 --- a/server/piztor/server.py +++ b/server/piztor/server.py @@ -18,12 +18,6 @@ from model import * def get_hex(data): return "".join([hex(ord(c))[2:].zfill(2) for c in data]) -def print_datagram(data): - print "==================================" - print "Received datagram:" - print get_hex(data) - print "==================================" - db_path = "piztor.sqlite" FORMAT = "%(asctime)-15s %(message)s" logging.basicConfig(format = FORMAT) @@ -93,13 +87,21 @@ class RequestHandler(object): class UserAuthHandler(RequestHandler): - _user_auth_response_size = \ + _response_size = \ _SectionSize.LENGTH + \ _SectionSize.OPT_ID + \ _SectionSize.STATUS + \ _SectionSize.USER_ID + \ _SectionSize.USER_TOKEN + _failed_response = \ + struct.pack("!LBBL32s", _response_size, + _OptCode.user_auth, + _StatusCode.failure, + 0, + bytes('\x00' * 32)) + + def handle(self, tr_data): logger.info("Reading auth data...") pos = -1 @@ -122,12 +124,7 @@ class UserAuthHandler(RequestHandler): .filter(UserModel.username == username).one() except NoResultFound: logger.info("No such user: {0}".format(username)) - return struct.pack("!LBBL32s", UserAuthHandler \ - ._user_auth_response_size, - _OptCode.user_auth, - _StatusCode.failure, - 0, - bytes('\x00' * 32)) + return UserAuthHandler._failed_response except MultipleResultsFound: raise DBCorruptedError() @@ -137,33 +134,22 @@ class UserAuthHandler(RequestHandler): raise DBCorruptedError() if not uauth.check_password(password): logger.info("Incorrect password: {0}".format(password)) - return struct.pack("!LBBL32s", UserAuthHandler \ - ._user_auth_response_size, - _OptCode.user_auth, - _StatusCode.failure, - 0, - bytes('\x00' * 32)) + return UserAuthHandler._failed_response else: logger.info("Logged in sucessfully: {0}".format(username)) uauth.regen_token() session.commit() - print "new token generated: " + get_hex(uauth.token) - return struct.pack("!LBBL32s", UserAuthHandler \ - ._user_auth_response_size, - _OptCode.user_auth, - _StatusCode.sucess, - user.id, - uauth.token) + logger.info("new token generated: " + get_hex(uauth.token)) + return struct.pack("!LBBL32s", UserAuthHandler._response_size, + _OptCode.user_auth, + _StatusCode.sucess, + user.id, + uauth.token) class LocationUpdateHandler(RequestHandler): -# _location_update_size = \ -# _SectionSize.AUTH_HEAD + \ -# _SectionSize.LATITUDE + \ -# _SectionSize.LONGITUDE - - _location_update_response_size = \ + _response_size = \ _SectionSize.LENGTH + \ _SectionSize.OPT_ID + \ _SectionSize.STATUS @@ -189,8 +175,7 @@ class LocationUpdateHandler(RequestHandler): # Authentication failure if uauth is None: logger.warning("Authentication failure") - return struct.pack("!LBB", LocationUpdateHandler \ - ._location_update_response_size, + return struct.pack("!LBB", LocationUpdateHandler._response_size, _OptCode.location_update, _StatusCode.failure) @@ -200,19 +185,14 @@ class LocationUpdateHandler(RequestHandler): session.commit() logger.info("Location is updated sucessfully") - return struct.pack("!LBB", LocationUpdateHandler \ - ._location_update_response_size, + return struct.pack("!LBB", LocationUpdateHandler._response_size, _OptCode.location_update, _StatusCode.sucess) class LocationRequestHandler(RequestHandler): -# _location_request_size = \ -# _SectionSize.AUTH_HEAD + \ -# _SectionSize.GROUP_ID - @classmethod - def _location_request_response_size(cls, item_num): + def _response_size(cls, item_num): return _SectionSize.LENGTH + \ _SectionSize.OPT_ID + \ _SectionSize.STATUS + \ @@ -239,15 +219,14 @@ class LocationRequestHandler(RequestHandler): # Auth failure if uauth is None: logger.warning("Authentication failure") - return struct.pack("!LBB", LocationRequestHandler \ - ._location_request_response_size(0), + return struct.pack("!LBB", LocationRequestHandler._response_size(0), _OptCode.location_request, _StatusCode.failure) ulist = session.query(UserModel).filter(UserModel.gid == gid).all() reply = struct.pack( "!LBB", - LocationRequestHandler._location_request_response_size(len(ulist)), + LocationRequestHandler._response_size(len(ulist)), _OptCode.location_request, _StatusCode.sucess) @@ -276,7 +255,6 @@ class UserInfoRequestHandler(RequestHandler): _OptCode.user_info_request, _StatusCode.failure) - _code_map = {0x00 : ('gid', pack_int), 0x01 : ('sex', pack_bool)} -- cgit v1.2.3 From 4431b44e5e5f0aa765a00872cb74303d7bc2db78 Mon Sep 17 00:00:00 2001 From: sjtufs Date: Mon, 26 Aug 2013 12:47:18 +0800 Subject: update ui --- client/Piztor/res/drawable/bottom_img.png | Bin 525331 -> 0 bytes client/Piztor/res/drawable/data.jpg | Bin 0 -> 686402 bytes client/Piztor/res/drawable/piztor.png | Bin 0 -> 3245 bytes client/Piztor/res/layout/activity_gather.xml | 8 + client/Piztor/res/layout/activity_init.xml | 24 +-- client/Piztor/res/layout/activity_login.xml | 141 +++++++------- client/Piztor/res/layout/activity_main.xml | 12 +- client/Piztor/res/layout/activity_settings.xml | 244 +++++++++++++------------ client/Piztor/res/layout/new_login.xml | 54 ++++++ 9 files changed, 280 insertions(+), 203 deletions(-) delete mode 100644 client/Piztor/res/drawable/bottom_img.png create mode 100644 client/Piztor/res/drawable/data.jpg create mode 100644 client/Piztor/res/drawable/piztor.png create mode 100644 client/Piztor/res/layout/new_login.xml diff --git a/client/Piztor/res/drawable/bottom_img.png b/client/Piztor/res/drawable/bottom_img.png deleted file mode 100644 index 2725ea8..0000000 Binary files a/client/Piztor/res/drawable/bottom_img.png and /dev/null differ diff --git a/client/Piztor/res/drawable/data.jpg b/client/Piztor/res/drawable/data.jpg new file mode 100644 index 0000000..f549ec7 Binary files /dev/null and b/client/Piztor/res/drawable/data.jpg differ diff --git a/client/Piztor/res/drawable/piztor.png b/client/Piztor/res/drawable/piztor.png new file mode 100644 index 0000000..7b6698a Binary files /dev/null and b/client/Piztor/res/drawable/piztor.png differ diff --git a/client/Piztor/res/layout/activity_gather.xml b/client/Piztor/res/layout/activity_gather.xml index f887cf0..9bc7ea4 100644 --- a/client/Piztor/res/layout/activity_gather.xml +++ b/client/Piztor/res/layout/activity_gather.xml @@ -20,4 +20,12 @@ > + diff --git a/client/Piztor/res/layout/activity_init.xml b/client/Piztor/res/layout/activity_init.xml index 43e6253..aa9cf66 100644 --- a/client/Piztor/res/layout/activity_init.xml +++ b/client/Piztor/res/layout/activity_init.xml @@ -1,16 +1,16 @@ - + + android:orientation="vertical" + android:id="@+id/init_layout" + android:background="@android:color/black"> - + - + diff --git a/client/Piztor/res/layout/activity_login.xml b/client/Piztor/res/layout/activity_login.xml index cd2d34c..b1f2f5b 100644 --- a/client/Piztor/res/layout/activity_login.xml +++ b/client/Piztor/res/layout/activity_login.xml @@ -1,11 +1,13 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - -