コード例 #1
0
ファイル: __init__.py プロジェクト: duruo850/HomeInternet
    def get(self, access_token, user_name_ls=None):
        """
        http get 请求
        :param access_token:访问码
        :param user_name_ls: 用户名列表
        :return:[user_dic,,,,]
        """
        user_name_ls = ujson.loads(user_name_ls)

        if not access_token\
                or not user_name_ls:
            return {'result': error_code.ERROR_PARAMS_ERROR}

        if not TokenMgr.check_expire_access_token(access_token):
            return {'result': error_code.ERROR_ACCESS_TOKEN_ERROR}

        result = {'result': error_code.ERROR_SUCCESS}
        connects = ServiceMgrCacher().get_connections(US_REGISTER_DA, RT_HASH_RING, user_name_ls)
        for connect, name_ls in connects.items():
            params = {"user_name_ls": name_ls}
            user_info_ls = user_select(connect, **params)
            [user_dic.__setitem__('device_type', get_device_type(ParamCacher().sm_rpc, user_dic['device_type']))
             for user_dic in user_info_ls
             if user_dic['device_type']]
            result.setdefault('user_info_ls', []).extend(user_info_ls)
        return result
コード例 #2
0
ファイル: __init__.py プロジェクト: duruo850/HomeInternet
    def verify_access_token(self, access_token):
        """
        验证访问码的有效性
        :param access_token:
        :return:{}
        """
        if not access_token:
            return {'result': error_code.ERROR_PARAMS_ERROR}

        return {'result': error_code.ERROR_SUCCESS,
                "validate": TokenMgr.check_expire_access_token(access_token)}
コード例 #3
0
ファイル: __init__.py プロジェクト: duruo850/HomeInternet
    def get(self, user_name, password, verify_code=None, type=None, param_sign=None, proxy_sign=None):
        """
        登陆
        :param verify_code: 客户端验证码
        :param user_name: 用户名
        :param password: 密码
        :param type:用户类型,1:控制端,2:设备端
        :param param_sign: 参数签名,用户调过验证码, 签名参数=verify_code, user_name, password
        :param proxy_sign: 代理签名,用于代理服务器的签名设置
        :return:
        """
        if not user_name\
                or not password\
                or not int(type) in enum.USER_TYPE_LS if type else False:
            return {'result': error_code.ERROR_PARAMS_ERROR}

        # 如果有param_sign,可使用验证param_sign越过验证码
        is_privilege = Signer().check_sign(param_sign, verify_code, user_name, password) \
            if param_sign \
            else False

        # 不使用验证码
        if type and int(type) in enum.NOT_VERIFY_CODE_USER_LS:
            is_privilege = True

        if not is_privilege:
            if not cookie.check_cookie(self, "register_verify_code", verify_code):
                logger.error("LoginHandle check_cookie failed!!!, verify_code:%s\n,param_sign:%s\n, HTTP_SGIN:%s"
                             % (verify_code, param_sign, HTTP_SIGN))
                return {'result': error_code.ERROR_VERIFY_CODE_ERROR}

        rgst_da_tcp = ServiceMgrCacher().get_connection(US_REGISTER_DA, RT_HASH_RING, user_name)
        user_info = get_user_info(rgst_da_tcp, user_name)
        if not user_info or user_info['password'] != password:
            return {'result': error_code.ERROR_USER_NAME_OR_PASSWORD_ERROR}
        elif type and int(user_info['type']) != int(type):
            return {'result': error_code.ERROR_PARAMS_ERROR}

        result = {"result": error_code.ERROR_SUCCESS,
                  "user_info": sub_dict(user_info, ["user_name", "jid", "jid_pwd", "type", "des"], ""),
                  "access_token": TokenMgr.generate_access_token(user_name)}

        if ArgumentParser().args.use_sign:
            result['sign'] = proxy_sign if proxy_sign else HTTP_SIGN
        return result
コード例 #4
0
ファイル: __init__.py プロジェクト: duruo850/HomeInternet
    def get_users(self, access_token, user_name_ls):
        """
        获取用户信息
        :param access_token: 访问码
        :param user_name_ls: 用户名列表
        :return:[user_dic,,,,]
        """
        if not access_token\
                or not user_name_ls:
            return {'result': error_code.ERROR_PARAMS_ERROR}

        if not TokenMgr.check_expire_access_token(access_token):
            return {'result': error_code.ERROR_ACCESS_TOKEN_ERROR}

        result = {'result': error_code.ERROR_SUCCESS}
        connects = ServiceMgrCacher().get_connections(US_REGISTER_DA, RT_HASH_RING, user_name_ls)
        for connect, name_ls in connects.items():
            params = {"user_name_ls": name_ls}
            user_info_ls = result.setdefault('user_info_ls', [])
            user_info_ls.extend(user_select(connect, **params))
        return result