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)
Beispiel #2
0
    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)