本文整理汇总了Python中model.User.User.add_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.add_user方法的具体用法?Python User.add_user怎么用?Python User.add_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User.User
的用法示例。
在下文中一共展示了User.add_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LoginHandler
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import add_user [as 别名]
class LoginHandler(UserHandler):
def initialize(self, service_config, mysql_handler, redis_handler, LOG):
super(UserHandler, self).initialize()
self.mysql_handler = mysql_handler
self.redis_handler = redis_handler
self.LOG = LOG
self.user = User(mysql_handler, LOG)
self.picture = Picture(mysql_handler, LOG)
self.rsp_handler = CommResponse()
self.show_account = service_config['show_account']
return
def verify_security_code(self, user_phone, security_code):
key = 'security:%s' % user_phone
field = 'security_code'
save_code = self.redis_handler.redis_conn.hget(key, field)
if security_code.upper() == save_code:
self.redis_handler.redis_conn.delete(key)
self.LOG.info('this user [%s] sms verify successful.' % user_phone)
return True
else:
self.LOG.error('this user [%s] sms verify failed.' % user_phone)
return False
def post(self):
self.LOG.debug('this is %s' % self.__class__.__name__)
try:
request_json = json.loads(self.request.body)
self.LOG.info(request_json)
user_phone = request_json['user_phone']
user_phone_mno = request_json['user_phone_mno']
security_code = request_json['security_code']
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 user_phone != self.show_account:
if not self.verify_security_code(user_phone, security_code):
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21002', None)
self.write(self.rsp_msg)
return
user_info = self.get_self_info(user_phone)
if user_info:
if user_info['login_status'] == 'login' and user_info['user_login_mobile_uuid'] != user_login_mobile_uuid:
modify_info = {
'user_login_mobile_uuid': user_login_mobile_uuid
}
else: #elif user_info['login_status'] != 'login':
modify_info = {
'login_status': 'login',
'user_login_mobile_uuid': user_login_mobile_uuid
}
self.user.modify_user(user_phone, modify_info)
user_info['user_login_mobile_uuid'] = user_login_mobile_uuid
rsp_data = {
'rsp_data': {
'user': user_info
}
}
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', rsp_data)
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return
ret, user_id = self.user.add_user(user_phone, user_phone_mno, user_login_mobile_uuid)
if not ret:
self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None)
self.mysql_handler.rollback_db()
self.write(self.rsp_msg)
return
user_info = self.get_self_info(user_phone)
rsp_data = {
'rsp_data': {
'user': user_info
}
}
self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', rsp_data)
self.LOG.info('user [%s] login successful.' % user_phone)
self.LOG.debug(self.rsp_msg)
self.mysql_handler.commit_db()
self.write(self.rsp_msg)
return