def wrapper(*args, **kw): ckey = '' user_id = 'DEFAULT' request_util = RequestUtil() res = False if is_check_ckey: ckey = request_util.get_ckey(request) if ckey: if auth_ckey_url: try: r_data = {'ckey': ckey, 'system': 'meeting'} ret = requests.post(url=auth_ckey_url, json=r_data) if ret.json().get('ret'): if ret.json().get('data').get('d') != r_domain: return jsonify(ret=0, message="Error domain") res = True user_id = ret.json().get('data').get('u') except (requests.RequestException or KeyError) as e: meeting_logger.error("ckey api failed : {}".format(e)) # TODO notify developer to check # res = check_ckey(ckey, user_id) res, user_id = check_ckey(ckey) except Exception as e: meeting_logger.error("ckey api failed : {}".format(e)) else: res, user_id = check_ckey(ckey) if res: return func(user_id=user_id, ckey=ckey, *args, **kw) else: meeting_logger.info("user:{user} login failed, ckey : {ckey}, \ ".format(user=user_id, ckey=ckey)) return jsonify(ret=0, message="ckey check failed") return func(user_id=user_id, ckey=ckey, *args, **kw)
def wrapper(*args, **kw): ckey = '' user_id = 'DEFAULT' user = '' request_util = RequestUtil() res = False __args = request_util.get_request_args(request) user_id = __args.get('qtalkId', 'UNKOWN') user_domain = None if '@' in user_id: _user = user_id.split('@') user = _user[0] user_domain = _user[1] else: user = user_id if isinstance(r_domain, str): user_domain = r_domain user_id = user_id + '@' + user_domain if user_id in [ 'guanghui.yang@ejabhost1', 'jingyu.he@ejabhost1', 'chaos.dong@ejabhost1', 'binz.zhang@ejabhost1' ]: return func(user_id=user_id, args=__args, *args, **kw) elif is_check_ckey: ckey = request_util.get_ckey(request) if ckey: if auth_ckey_url: try: r_data = {'ckey': ckey, 'system': 'search'} ret = requests.post(url=auth_ckey_url, json=r_data) """{ "ret": true, "errcode": 0, "errmsg": "", "data": { "d": "qtalk.test.org", "u": "aaa.bb" } }""" if ret.json().get('ret') and ret.json().get( 'data', {}).get( 'u', '') + '@' + ret.json().get( 'data', {}).get('d', '') == user_id: if user_domain and ret.json().get('data').get( 'd') != user_domain: return jsonify(ret=False, errcode=500, msg="Error domain") # TODO remove this after domain check is soon needless elif not user_domain: user_domain = ret.json().get('data', {}).get('d') res = True # user = user_id + '@' + user_domain user = user + '@' + user_domain else: search_logger.error( "ckey api check failed : ret {} u {}".format( ret.json().get('ret'), user_id)) except (requests.RequestException or KeyError) as e: search_logger.error("ckey api failed : {}".format(e)) # TODO notify developer to check res, user = check_ckey(ckey) except Exception as e: search_logger.exception( "ckey api failed : {}".format(e)) else: res, user = check_ckey(ckey) if res: return func(user_id=user, args=__args, *args, **kw) else: search_logger.info("user:{user} login failed, ckey : {ckey}, \ ".format(user=user_id, ckey=ckey)) return jsonify(ret=False, errcode=0, message="ckey check failed") return func(user_id=user_id, args=__args, *args, **kw)
def main(): global ip, s_args args = RequestUtil.get_request_args(request) if not s_args: s_args = args try: username = args["key"].strip() user_id = args["qtalkId"].strip() except KeyError: return jsonify(ret=0, message="wrong parameters") if len(username) < 2: return jsonify(ret=0, message="length of key should greater than two") ckey = args.get("cKey", "") group_id = args.get("groupid", "") offset = int(args.get("start", 0)) limit = int(args.get("length", 5)) if is_check_ckey: res, user = check_ckey(ckey, user_id) if not res: logger.error('{} login FAILED. ckey : {}'.format(user_id, ckey)) return jsonify(ret=0, message="ckey failed") request_ip = request.remote_addr if ip != request_ip: ip = request_ip logger.info(ip + ' : {}'.format(json.dumps(s_args))) s_args = args result = list() data_array = list() userlib = UserLib() if group_id: if group_id == userGroup: user_array = userlib.search_user(username, user_id, limit + 1, offset) has_more, user_array = get_hasmore(user_array, limit) if user_array: result = make_result(label='联系人列表', groupid=userGroup, group_priority=0, todo_type=QTALK_OPEN_USER_VCARD, portrait=single_portrait, hasmore=has_more, info=user_array) elif group_id == groupGroup: group_array = userlib.search_group(user_id, username, limit + 1, offset) has_more, group_array = get_hasmore(group_array, limit) if group_array: result = make_result(label='群组列表', groupid=groupGroup, group_priority=0, todo_type=QTALK_OPEN_GROUP_VCARD, portrait=muc_portrait, hasmore=has_more, info=group_array) elif group_id == commonGroup: commonmuc_array = userlib.search_group_by_single( user_id, username, limit + 1, offset) has_more, commonmuc_array = get_hasmore(commonmuc_array, limit) if commonmuc_array: result = make_result(label='共同群组', groupid=commonGroup, group_priority=0, todo_type=QTALK_OPEN_GROUP_VCARD, portrait=muc_portrait, hasmore=has_more, info=commonmuc_array) else: return jsonify(errcode=500, msg='无法预期的groupId') userlib.conn.close() return jsonify(errcode=0, msg='', data=result) else: user_array = userlib.search_user(username, user_id, limit + 1, offset) group_array = userlib.search_group(user_id, username, limit + 1, offset) commonmuc_array = userlib.search_group_by_single( user_id, username, limit + 1, offset) if user_array: has_more, user_array = get_hasmore(array=user_array, limit=limit) result = make_result(label='联系人列表', groupid=userGroup, group_priority=0, todo_type=QTALK_OPEN_USER_VCARD, portrait=single_portrait, hasmore=has_more, info=user_array) data_array.append(result) if group_array: has_more, group_array = get_hasmore(array=group_array, limit=limit) result = make_result(label='群组列表', groupid=groupGroup, group_priority=0, todo_type=QTALK_OPEN_GROUP_VCARD, portrait=muc_portrait, hasmore=has_more, info=group_array) data_array.append(result) if commonmuc_array: has_more, commonmuc_array = get_hasmore(commonmuc_array, limit) result = make_result(label='共同群组', groupid=commonGroup, group_priority=0, todo_type=QTALK_OPEN_GROUP_VCARD, portrait=muc_portrait, hasmore=has_more, info=commonmuc_array) data_array.append(result) userlib.conn.close() return jsonify(errcode=0, msg='', data=data_array)