def prepare(self): """ 请求前的操作 """ ret = self.check_must_have_param() if ret: return self.finish(ret) path = self.request.path user_id = common.my_int(self.get_argument('user_id', 0)) # 校验登录态 if path not in not_need_xyy: xyy = common.my_str(self.get_argument("xyy", '')) if not common.check_user_sid(user_id, xyy): return self.finish(common.Err(err_conf.E_BAD_XYY)) request_data = self.parse_request_body() # 验证签名 sign_info = check_sign.is_right_sign(path, request_data) reason = {} if isinstance(sign_info, tuple): sign_flag, reason = sign_info else: sign_flag = sign_info if not sign_flag: ret = common.Err(err_conf.ES_BAD_PARAM) error_code = reason.get('code', 0) if error_code == err_conf.E_BAD_SESSION: ret = common.Err(err_conf.E_BAD_SESSION) reason = json.dumps(reason, ensure_ascii=False, indent=4) ApiGraylog(request_data.get('user_id', 0), 'waterworld_bad_sign', path, request_data.get('ver', ''), reason, self.request) self.finish(ret) return
def post(self): """ 处理请求参数 """ phone = common.my_str(self.get_argument('phone')) app_package = common.my_str(self.get_argument('app_package')) verify_code = common.my_int(self.get_argument('verify_code')) is_right_phone = common.is_right_phone(phone) if not is_right_phone: return self.finish(err_conf.E_BAD_PHONE) sms_code = 0 now = int(time.time()) send_ts = 0 sql = """select code, unix_timestamp(ts) as ts from phone_code_tickets64 where phone={0} order by ts desc limit 1""".format(int(phone)) result = self.db_handle.query(sql) for item in result: sms_code = item.code send_ts = item.ts if verify_code != sms_code: return self.finish(common.Err(err_conf.E_BAD_CHECK_PHONE_CODE)) # 验证码5分钟内有效 if now - send_ts > 5 * 60: return self.finish(common.Err(err_conf.E_PHONE_CODE_EXPIRE)) # 生成token string_token = "{0}{1}{2}".format(phone, app_package, now) access_token = self.auth_handle.genarate_access_token(string_token) self.db_redis.set(access_token, phone, ex=5 * 60) response = {'code': 0, 'msg': 'ok', "access_token": access_token} return self.finish(response)
def post(self): user_id = common.my_int(self.get_argument('user_id')) xyy = common.my_str(self.get_argument("xyy")) if not common.check_user_sid(user_id, xyy): return self.finish(common.Err(err_conf.E_BAD_XYY)) user_info = self.user_handle.get_user_info(user_id) response = dict(code=0, msg="ok", user_info=user_info) return self.finish(response)
def post(self): user_id = common.my_int(self.get_argument('user_id')) sex = common.my_int(self.get_argument('sex', None)) height = common.my_int(self.get_argument('height', None)) weight = common.my_int(self.get_argument('weight', None)) nick = common.my_str(self.get_argument('nick', None)) birthday = common.my_int(self.get_argument('birthday', None)) blood_type = common.my_str(self.get_argument('blood_type', None)) blood_pressure = common.my_str(self.get_argument('blood_pressure', None)) heart_rate = common.my_int(self.get_argument('heart_rate', None)) blood_sugar = common.my_int(self.get_argument('blood_sugar', None)) args = dict( user_id=user_id, nick=common.text_filter(nick), sex=sex, height=height, weight=weight, birthday=birthday, blood_pressure=blood_pressure, blood_sugar=blood_sugar, blood_type=blood_type, heart_rate=heart_rate ) self.user_handle.update_user_info(args) return self.finish(common.Ok())
def post(self): """ 1. 更改用户状态为删除 2. 解除绑定open_id 3. 清除登录态 """ user_id = common.my_int(self.get_argument('user_id')) args = dict(user_id=user_id, status=9) self.user_handle.update_user_info(args) self.user_handle.unbind_user_opendid_info(user_id) common.remove_user_sid(user_id)
def post(self): """ 处理请求 """ user_id = common.my_int(self.get_argument('user_id')) phone = common.my_str(self.get_argument('phone')) access_token = common.my_str(self.get_argument('access_token')) user_phone = self.db_redis.get(access_token) if user_phone != phone: return self.finish(common.Err("无效的token或手机号!")) bind_user_id = self.auth_handle.get_user_id_by_phone(phone) if user_id != bind_user_id: return self.finish(common.Err("当前手机号已经绑定其他的微信/QQ账号!")) self.auth_handle.bind_phone(user_id, phone) return self.finish(common.Ok())
def post(self): """ 处理请求 """ file_metas = self.request.files['logo_file'] user_id = common.my_int(self.get_argument('user_id', 0)) filename = file_body = "" for meta in file_metas: filename = meta['filename'] file_body = meta['body'] if filename == "" or file_body == "": return self.finish(common.Err(err_conf.E_BAD_UPLOAD_HEAD)) ret = self.user_handle.upload_head_url(user_id, file_body) head_url = "" if ret: head_url = common.get_user_head_url(user_id) return self.finish(dict(head_url=head_url))
def post(self): user_id = common.my_int(self.get_argument("user_id", 0)) session_key, ttl = self.auth_handle.get_user_session_key(user_id) response = dict(code=0, msg="ok", session_key=session_key, ttl=ttl) return self.finish(response)
def send_to_graylog_tornado(gelf_data, req=None, path=None, req_data=None): """ 发送日志到graylog """ if 'source' in gelf_data or '_source' in gelf_data: return if 'short_message' not in gelf_data: return message = gelf_data['short_message'].replace(' ', '') import utils.myCache log_rule = utils.myCache.Cacheing.GetLogRule() if message not in log_rule: print("send log fail >>>> short_message not in log_rule table") return try: hash_id = int(log_rule[message]['hash_id']) except: hash_id = 0 if req_data is None and req is None: data = "None" elif req_data is None and req is not None: data = req.arguments else: data = req_data if isinstance(data, dict): if '_user_id' not in gelf_data: user_id = common.my_int( data.get('user_id', [0])[0].decode('utf-8')) if user_id == '': user_id = 0 if user_id > 10000: gelf_data['_user_id'] = user_id key_list = [ 'ver', 'phone_type', 'channel', 'os', 'package_name', 'source' ] for key in key_list: if key not in data: continue if '_{0}'.format(key) not in gelf_data: value = data.get(key, [''])[0].decode('utf-8') if key == 'source': key = 'platform' if value: gelf_data['_{0}'.format(key)] = value if '_uri' not in gelf_data: if not path: path = req.uri if path: gelf_data['_uri'] = path if hash_id > 0 and '_user_id' in gelf_data: user_id = int(gelf_data['_user_id']) if user_id % 100 >= hash_id: pass ## 非测试用户灰度上报, # is_test_user = True if user_id in myBF.getTestUserBF() else False # if not is_test_user: # return if '_user_id' in gelf_data and '_tail_number' not in gelf_data: gelf_data['_tail_number'] = int(gelf_data['_user_id']) % 100 if '_phone_type' in gelf_data: phone_type = gelf_data['_phone_type'] if isinstance(phone_type, str) and phone_type: phone_type_arr = phone_type.split("_") if len(phone_type_arr) >= 3: gelf_data['_model'] = phone_type_arr[0] gelf_data['_phone'] = phone_type_arr[1] gelf_data['_os'] = str(phone_type_arr[2]) elif 'iPhone' in phone_type: gelf_data['_model'] = 'iPhone' gelf_data['_phone'] = phone_type del gelf_data['_phone_type'] if 'level' not in gelf_data: gelf_data['level'] = 7 try: log_gelf_udp.log(gelf_data) except: send_try_except()