本文整理汇总了Python中model.User.User.check_login_status方法的典型用法代码示例。如果您正苦于以下问题:Python User.check_login_status方法的具体用法?Python User.check_login_status怎么用?Python User.check_login_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User.User
的用法示例。
在下文中一共展示了User.check_login_status方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AffirmHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class AffirmHandler(tornado.web.RequestHandler):
def initialize(self, service_config, mysql_handler, redis_handler, LOG):
self.push_queue = service_config['push_message_queue']
self.mysql_handler = mysql_handler
self.redis_handler = redis_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.order = Order(mysql_handler, LOG)
self.rsp_handler = CommResponse()
return
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
order_number = request_json['order_info']['order_number']
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.write(self.rsp_msg)
return
order_info = self.order.verify_order_status(order_number, 'submit')
if not order_info:
self.LOG.error('order [%s] is not exist or order status not allowed to modify' % order_number)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21010', None)
self.write(self.rsp_msg)
return
modify_info = {'order_status': 'affirm'}
if not self.order.modify_order(order_number, modify_info):
self.LOG.error('modify order [%s] into mysql failed.' % order_number)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None)
self.write(self.rsp_msg)
return
push_msg = {
'target_users': [order_info['order_buyer']],
'message': MESSAGE['affirm_seller']
}
self.redis_handler.redis_conn.lpush(self.push_queue, json.dumps(push_msg))
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', None)
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
示例2: RemoveHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class RemoveHandler(tornado.web.RequestHandler):
def initialize(self, mysql_handler, LOG):
self.mysql_handler = mysql_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.device = Device(mysql_handler, LOG)
self.favorite = Favorite(mysql_handler, LOG)
self.rsp_handler = CommResponse()
return
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
collection_type = request_json['collection_type']
collection_name = request_json['collection_name']
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.write(self.rsp_msg)
return
(ret, num) = self.favorite.remove_collection(user_phone, collection_name, collection_type)
if not ret:
self.LOG.error('delete collection from mysql failed.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None)
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
if num:
modify_info = {
'collected': 'collected - 1'
}
if collection_type == 'user':
self.user.modify_user(collection_name, modify_info)
elif collection_type == 'device':
self.device.modify_device(collection_name, modify_info)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', None)
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
示例3: ModifyHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class ModifyHandler(tornado.web.RequestHandler):
def initialize(self, mysql_handler, LOG):
self.mysql_handler = mysql_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.order = Order(mysql_handler, LOG)
self.rsp_handler = CommResponse()
return
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
order_info = request_json['order_info']
order_number = request_json['order_info']['order_number']
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.write(self.rsp_msg)
return
if not self.order.verify_order_status(order_number, 'submit'):
self.LOG.error('order [%s] is not exist or order status not allowed to modify' % order_number)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21010', None)
self.write(self.rsp_msg)
return
del order_info['order_number']
if not self.order.modify_order(order_number, order_info):
self.LOG.error('modify order [%s] into mysql failed.' % order_number)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None)
self.write(self.rsp_msg)
return
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', None)
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
示例4: LogoutHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class LogoutHandler(UserHandler):
def initialize(self, mysql_handler, LOG):
super(UserHandler, self).initialize()
self.mysql_handler = mysql_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.rsp_handler = CommResponse()
return
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
self.LOG.debug(self.request.body)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
self.LOG.info('user_phone is [%s]' % user_phone)
self.LOG.info('user_login_mobile_uuid is [%s]' % user_login_mobile_uuid)
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.write(self.rsp_msg)
return
if not self.user.loginout(user_phone):
self.LOG.error('user [%s] logout failed.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None)
self.write(self.rsp_msg)
return
self.LOG.info('user [%s] logout successful.' % user_phone)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', None)
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
示例5: VerifyHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class VerifyHandler(UserHandler):
def initialize(self, mysql_handler, LOG):
super(UserHandler, self).initialize()
self.mysql_handler = mysql_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.rsp_handler = CommResponse()
return
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
company_license = request_json['company_license']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.write(self.rsp_msg)
return
if self.user.check_license_exist(company_license):
self.LOG.error('company license [%s] already exist.' % company_license)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21004', None)
self.write(self.rsp_msg)
return
self.LOG.info('user [%s] verify successful.' % user_phone)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', None)
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
示例6: SearchHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class SearchHandler(UserHandler):
def initialize(self, mysql_handler, LOG):
super(UserHandler, self).initialize()
self.mysql_handler = mysql_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.picture = Picture(mysql_handler, LOG)
self.rsp_handler = CommResponse()
return
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
target_user = request_json['condition']['user_phone']
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.write(self.rsp_msg)
return
user_info = self.get_self_info(target_user)
rsp_data = {
'user': user_info
}
self.LOG.info('user [%s] search successful.' % user_phone)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', {'rsp_data': rsp_data})
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
示例7: ListHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class ListHandler(tornado.web.RequestHandler):
def initialize(self, mysql_handler, LOG):
self.mysql_handler = mysql_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.order = Order(mysql_handler, LOG)
self.evaluation = Evaluation(mysql_handler, LOG)
self.device = Device(mysql_handler, LOG)
self.picture = Picture(mysql_handler, LOG)
self.device_attribute = DeviceAttribute(mysql_handler, LOG)
self.rsp_handler = CommResponse()
return
def post(self):
self.LOG.info('this is %s' % self.__class__.__name__)
self.LOG.debug(self.request.headers)
self.LOG.debug(self.request.body)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
user_role = request_json['order_info']['role']
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.write(self.rsp_msg)
return
if user_role == 'buyer':
condition = {'order_buyer': user_phone}
elif user_role == 'seller':
condition = {'order_seller': user_phone}
else:
self.LOG.debug('user role [%s] invalid' % user_role)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21011', None)
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
orders = self.order.get_order(condition)
if not orders:
self.LOG.error('user [%s] as role [%s] has no orders.' % (user_phone, user_role))
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', {'rsp_data': {'orders':[]}})
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
for order in orders:
device_info = {}
device_info = self.device.get_device_by_number(order['order_device'])
if not device_info:
device_info = {}
else:
device_attributes = self.device_attribute.get_attribute_by_number(device_info['device_number'])
device_info['device_attributes'] = device_attributes if device_attributes else []
device_pictures = self.picture.get_image_by_number(device_info['device_number'], 'device')
if device_pictures:
for picture in device_pictures:
del picture['pic_owner_mark']
del picture['create_time']
del picture['pic_path']
del picture['pic_owner_type']
device_info['device_pictures'] = device_pictures if device_pictures else []
order['device_info'] = dict(device_info.items())
evaluation_info = self.evaluation.get_evaluation(order['order_number'])
order['evaluation_text'] = evaluation_info['evaluation_text'] if evaluation_info else ''
order['evaluation_time'] = evaluation_info['evaluation_time'] if evaluation_info else ''
order['evaluation_level'] = evaluation_info['evaluation_level'] if evaluation_info else 0
order['feedback_text'] = evaluation_info['feedback_text'] if evaluation_info else ''
order['feedback_time'] = evaluation_info['feedback_time'] if evaluation_info else ''
rsp_data = {
'rsp_data': {'orders': orders}
}
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', rsp_data)
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
示例8: FeedbackHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class FeedbackHandler(tornado.web.RequestHandler):
def initialize(self, service_config, mysql_handler, redis_handler, LOG):
self.push_queue = service_config['push_message_queue']
self.mysql_handler = mysql_handler
self.redis_handler = redis_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.order = Order(mysql_handler, LOG)
self.evaluation = Evaluation(mysql_handler, LOG)
self.rsp_handler = CommResponse()
return
def generate_redis_time(self):
now = self.redis_handler.redis_conn.time()[0]
return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(now))
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
order_number = request_json['order_info']['order_number']
order_device = request_json['order_info']['order_device']
feedback_text = request_json['order_info']['text']
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.write(self.rsp_msg)
return
order_info = self.order.verify_order_status(order_number, 'evaluate')
if not order_info:
self.LOG.error('order [%s] is not exist or order status not allowed to modify' % order_number)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21010', None)
self.write(self.rsp_msg)
return
now_time = self.generate_redis_time()
if not self.evaluation.modify_evaluation(order_number, order_device, feedback_text, now_time):
self.LOG.error('insert evaluation into mysql failed.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None)
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
modify_info = {'order_status': 'feedback'}
if not self.order.modify_order(order_number, modify_info):
self.LOG.error('modify order [%s] into mysql failed.' % order_number)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None)
self.write(self.rsp_msg)
return
push_msg = {
'target_users': [order_info['order_buyer']],
'message': MESSAGE['feedback']
}
self.redis_handler.redis_conn.lpush(self.push_queue, json.dumps(push_msg))
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', None)
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
示例9: SubmitHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class SubmitHandler(tornado.web.RequestHandler):
def initialize(self, service_config, mysql_handler, redis_handler, LOG):
self.push_queue = service_config['push_message_queue']
self.mysql_handler = mysql_handler
self.redis_handler = redis_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.order = Order(mysql_handler, LOG)
self.rsp_handler = CommResponse()
return
def generate_order_number(self):
sequence = self.redis_handler.redis_conn.hincrby('sequence', 'order', 1)
now = self.redis_handler.redis_conn.time()[0]
return 'CF%s%08d' % (time.strftime('%Y%m%d', time.localtime(now)), sequence)
def generate_redis_time(self):
now = self.redis_handler.redis_conn.time()[0]
return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(now))
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
order_info = request_json['order_info']
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.write(self.rsp_msg)
return
order_number = self.generate_order_number()
now_time = self.generate_redis_time()
order_info['order_number'] = order_number
order_info['create_time'] = now_time
(ret, num, id) = self.order.add_order(order_info)
if not ret:
self.LOG.error('insert collection into mysql failed.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None)
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
push_msg = {
'target_users': [order_info['order_seller']],
'message': MESSAGE['submit']
}
self.redis_handler.redis_conn.lpush(self.push_queue, json.dumps(push_msg))
rsp_data = {'order_number': order_number}
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', {'rsp_data': rsp_data})
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
示例10: ShowHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class ShowHandler(tornado.web.RequestHandler):
def initialize(self, mysql_handler, LOG):
self.mysql_handler = mysql_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.device = Device(mysql_handler, LOG)
self.favorite = Favorite(mysql_handler, LOG)
self.picture = Picture(mysql_handler, LOG)
self.device_attribute = DeviceAttribute(mysql_handler, LOG)
self.rsp_handler = CommResponse()
return
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
collection_type = request_json['collection_type']
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
collections = self.favorite.get_collection(user_phone, collection_type)
if not collections:
self.LOG.error('user [%s] has no collections.' % user_phone)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', {'rsp_data': {'collections':[]}})
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
result = []
targets = [collection['collection_mark'] for collection in collections]
if collection_type == 'user':
users = self.user.get_user_by_phones(targets)
for user in users:
image_info = self.picture.get_image_by_phone(user['user_phone'], 'user')
try:
image_big_mame = image_info['pic_big_name']
image_sml_mame = image_info['pic_sml_name']
except:
image_big_mame = None
image_sml_mame = None
user['pic_big_name'] = image_big_mame
user['pic_sml_name'] = image_sml_mame
del user['user_login_mobile_uuid']
del user['user_phone_mno']
result = users
elif collection_type == 'device':
devices = self.device.get_device_by_numbers(targets)
for device in devices:
attributes = self.device_attribute.get_attribute_by_number(device['device_number'])
device['device_attributes'] = attributes if attributes else []
pictures = self.picture.get_image_by_number(device['device_number'], 'device')
if pictures:
for picture in pictures:
del picture['pic_owner_mark']
del picture['create_time']
del picture['pic_path']
del picture['pic_owner_type']
device['device_pictures'] = pictures if pictures else []
device['user_phone']
result = devices
else:
self.LOG.error('collection_type [%s] is error.' % collection_type)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None)
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', {'rsp_data': {'collections':result}})
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
示例11: PushTokenHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class PushTokenHandler(UserHandler):
def initialize(self, mysql_handler, LOG):
super(UserHandler, self).initialize()
self.mysql_handler = mysql_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.push_token = PushToken(mysql_handler, LOG)
self.rsp_handler = CommResponse()
return
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
self.LOG.debug(self.request.body)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
user_push_token = request_json['user_push_token']
user_push_type = request_json['user_push_type']
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.write(self.rsp_msg)
return
if user_push_type != 'iOS' and user_push_type!= 'Android':
self.LOG.error('token type [%s] not valid.' % user_push_type)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21013', None)
self.write(self.rsp_msg)
return
token = self.push_token.get_token(user_phone)
if not token:
if user_push_type == 'iOS':
value = {
'user_phone': user_phone,
'user_ios_token': user_push_token
}
else:
value = {
'user_phone': user_phone,
'user_android_token': user_push_token
}
ret, id = self.push_token.add_token(value)
if not ret:
self.LOG.error('add push token [%s] failed.' % user_push_token)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21014', None)
self.write(self.rsp_msg)
return
else:
if user_push_type == 'iOS':
value = {
'user_ios_token': user_push_token
}
else:
value = {
'user_android_token': user_push_token
}
ret = self.push_token.update_token(user_phone, value)
if not ret:
self.LOG.error('modify push token [%s] failed.' % user_push_token)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21015', None)
self.write(self.rsp_msg)
return
self.LOG.info('user [%s] modify push token [%s] successful.' % (user_phone, user_push_token))
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', None)
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
示例12: DownloadHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class DownloadHandler(UserHandler):
def initialize(self, mysql_handler, LOG):
super(UserHandler, self).initialize()
self.mysql_handler = mysql_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.picture = Picture(mysql_handler, LOG)
self.rsp_handler = CommResponse()
self.image_path = None
return
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
self.LOG.debug(self.request.body)
try:
request_json = json.loads(self.request.body)
user_phone = request_json['user_phone']
user_login_mobile_uuid = request_json['user_login_mobile_uuid']
image_type = request_json['type_image']
image_file = request_json['file_image']
except Exception as e:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
try:
image_file.index('big')
image_name = str(image_file)
except:
image_name = image_file.replace('sml', 'big')
image_info = self.picture.get_image_by_name(image_type, image_name)
if not image_info:
self.LOG.error('image file [%s] is not exist in mysql.' % image_file)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21003', None)
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
local_file = os.path.join(image_info[0]['pic_path'], image_file)
if not os.path.isfile(local_file):
self.LOG.error('image file [%s] is not exist in disk.' % image_file)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21003', None)
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
self.set_header('Content-Type', 'application/octet-stream')
self.set_header('Content-Disposition', 'attachment; filename=' + image_info[0]['pic_big_name'])
with open(local_file, 'rb') as file_handler:
while True:
data = file_handler.read(4096)
if not data:
break
self.write(data)
self.LOG.info('user [%s] download [%s] successful.' % (user_phone, image_file))
self.finish()
return
示例13: LicenseUploadHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import check_login_status [as 别名]
class LicenseUploadHandler(UserHandler):
def initialize(self, service_config, mysql_handler, LOG):
super(UserHandler, self).initialize()
self.image_path = service_config['image_license_path']
self.mysql_handler = mysql_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.picture = Picture(mysql_handler, LOG)
self.compressHandler = CompressHandler(
service_config['compress_width'],
service_config['compress_height'],
service_config['compress_quality']
)
self.rsp_handler = CommResponse()
return
def recv_file(self, save_file_path, image_name, compress_name):
if not os.path.exists(save_file_path):
os.makedirs(save_file_path)
recv_file_name = os.path.join(save_file_path, '%s' % image_name)
save_file = self.request.files['file_image'][0]
fin = open(recv_file_name, "wb")
fin.write(save_file["body"])
fin.close()
self.compressHandler.compress_file(recv_file_name, os.path.join(save_file_path, '%s' % compress_name))
return
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
user_phone = self.get_argument('user_phone', None)
user_login_mobile_uuid = self.get_argument('user_login_mobile_uuid', None)
if not user_phone:
self.LOG.error('parameters error.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None)
self.write(self.rsp_msg)
return
if not self.user.check_login_status(user_phone, user_login_mobile_uuid):
self.LOG.error('user [%s] not login.' % user_phone)
self.mysql_handler.rollback_db()
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None)
self.write(self.rsp_msg)
return
image_big_name = '%s_license_big.jpg' % str(user_phone)
image_sml_name = '%s_license_sml.jpg' % str(user_phone)
self.picture.del_image(user_phone, 'license')
(ret, num, id) = self.picture.add_image(user_phone, 'license', image_big_name, image_sml_name, self.image_path)
if not ret:
self.LOG.error('add image to mysql failed.')
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None)
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
self.recv_file(self.image_path, image_big_name, image_sml_name)
self.LOG.info('user [%s] upload license successful.' % user_phone)
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', None)
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return