Example #1
0
def get_app_list(request):
    BaseResponse = BR()
    print(request.path)
    print(request.get_host())
    if request.method == 'GET':
        user_id = request.GET.get("userId")
        if user_id is None or user_id == '':
            BaseResponse.error_msg = 'userId can not be empty'
            return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
        user_model = mUser.objects.get(user_id=user_id)
        app_model = application.objects.values(
            'user_id',
            'app_id',
            'app_name',
            'app_url',
            'app_logo',
            'package_name',
            'version_name',
            'version_code',
            'min_sdk_version',
            'target_sdk_version',
        ).filter(user_id=user_model)
        BaseResponse.result = {"list": list(app_model)}
        BaseResponse.error_code = '1'
        BaseResponse.error_msg = ''
    return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
Example #2
0
def get_app(request):
    BaseResponse = BR()
    if request.method == 'GET':
        user_id = request.GET.get("userId")
        app_id = request.GET.get("appId")
        if user_id is None or user_id == '':
            BaseResponse.error_msg = 'userId can not be empty'
            return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
        if app_id is None or app_id == '':
            BaseResponse.error_msg = 'appId can not be empty'
            return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
        user_model = mUser.objects.get(userId=user_id)
        app_model = application.objects.get(userId=user_model, app_id=app_id)
        BaseResponse.result = app_model
    return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
Example #3
0
def get_plugin_list(request):
    BaseResponse = BR()
    if request.method == 'GET':
        app_id = request.GET.get("appId")
        if app_id is None or app_id == '':
            BaseResponse.error_msg = 'app id can not be empty'
            return HttpResponse(jsonTool.object_to_json(BaseResponse),
                                "application/json")
        application_model = ApplicationModel.objects.get(app_id=app_id)
        plugin_models = PluginModel.objects.values(
            "plugin_id", "app_id", "plugin_name", "plugin_description",
            "package_name", "last_version_name",
            "last_version_code").filter(app_id=application_model)
        BaseResponse.result = {"list": list(plugin_models)}
        BaseResponse.error_code = 1
        BaseResponse.error_msg = 'request success'
    return HttpResponse(jsonTool.object_to_json(BaseResponse),
                        "application/json")
Example #4
0
def get_apk(request):
    BaseResponse = BR()
    if request.method == 'GET':
        user_id = request.GET.get("userId")
        plugin_id = request.GET.get("pluginId")
        apk_id = request.GET.get("apkId")
        if plugin_id is None or plugin_id == '':
            BaseResponse.error_msg = 'plugin id can not be empty'
            return HttpResponse(jsonTool.object_to_json(BaseResponse),
                                "application/json")
        if apk_id is None or apk_id == '':
            BaseResponse.error_msg = 'apk id can not be empty'
            return HttpResponse(jsonTool.object_to_json(BaseResponse),
                                "application/json")
        BaseResponse.error_code = 1
        BaseResponse.result = ApkFileModel.objects.get(
            plugin_id=PluginModel.objects.get(plugin_id=plugin_id),
            apk_id=apk_id)
    return HttpResponse(jsonTool.object_to_json(BaseResponse),
                        "application/json")
Example #5
0
def get_plugin(request):
    BaseResponse = BR()
    if request.method == 'GET':
        app_id = request.GET.get("appId")
        plugin_id = request.GET.get("pluginId")
        if app_id is None or app_id == '':
            BaseResponse.error_msg = 'app id can not be empty'
            return HttpResponse(jsonTool.object_to_json(BaseResponse),
                                "application/json")
        if plugin_id is None or plugin_id == '':
            BaseResponse.error_msg = 'plugin id can not be empty'
            return HttpResponse(jsonTool.object_to_json(BaseResponse),
                                "application/json")
        application_model = ApplicationModel.objects.get(app_id=app_id)
        BaseResponse.result = PluginModel.objects.get(plugin_id=plugin_id,
                                                      app_id=application_model)
        BaseResponse.error_code = 1
        BaseResponse.error_msg = 'delete plugin success'
    return HttpResponse(jsonTool.object_to_json(BaseResponse),
                        "application/json")
Example #6
0
def user_login(request):
    base_response = BR()
    # userLogin
    if request.method == 'POST':
        username = request.POST.get('userName', '')
        password = request.POST.get('passWord', '')
        if username is None or username == '':
            base_response.error_msg = 'username can not be empty'
            return HttpResponse(jsonTool.object_to_json(base_response),
                                "application/json")
        if password is None or password == '':
            base_response.error_msg = 'password can not be empty'
            return HttpResponse(jsonTool.object_to_json(base_response),
                                "application/json")
        try:
            user = mUser.objects.values(
                'user_id', 'account_number', 'user_name', 'user_logo',
                'user_phone', 'pass_word').get(account_number=username)
        except FieldError:
            print(FieldError)
            base_response.error_msg = Error.Username_does_not_exist
            return HttpResponse(jsonTool.object_to_json(base_response),
                                "application/json")
        except mUser.DoesNotExist:
            base_response.error_msg = Error.Username_does_not_exist
            return HttpResponse(jsonTool.object_to_json(base_response),
                                "application/json")
        if user is not None and user['pass_word'] != password:
            base_response.error_msg = Error.Username_or_password_is_incorrect
            return HttpResponse(jsonTool.object_to_json(base_response),
                                "application/json")
        base_response.error_code = 1
        base_response.error_msg = Error.Login_Success
        del user['pass_word']
        base_response.result = user
        return HttpResponse(jsonTool.object_to_json(base_response),
                            "application/json")
    else:
        base_response.error_msg = Error.Request_method_error
        return HttpResponse(jsonTool.object_to_json(base_response),
                            "application/json")
Example #7
0
def up_load_file(request):
    base_response = BaseResponse()
    print(request.__dict__)
    if request.method == 'POST':
        user_id = request.POST.get("userId")
        print(user_id)
        if user_id is None or user_id == '':
            base_response.error_msg = 'user id can not be empty'
            return HttpResponse(jsonTool.object_to_json(base_response),
                                "application/json")
        try:
            user = UserModel.objects.get(user_id=user_id)
        except FieldError:
            base_response.error_msg = Error.Username_does_not_exist
            return HttpResponse(jsonTool.object_to_json(base_response),
                                "application/json")
        except UserModel.DoesNotExist:
            base_response.error_msg = Error.Username_does_not_exist
            return HttpResponse(jsonTool.object_to_json(base_response),
                                "application/json")
        if user is None:
            base_response.error_msg = 'user id can not be empty'
            return HttpResponse(jsonTool.object_to_json(base_response),
                                "application/json")
        apk_file = request.FILES['file']
        if apk_file is None:
            base_response.error_msg = 'file can not be empty'
            return HttpResponse(jsonTool.object_to_json(base_response),
                                "application/json")
        replace = uuid.uuid1().__str__().replace('-', '')
        file_path = save_apk_file(apk_file, replace + '.png', user_id)
        file_model = FileModel.objects.create(
            user_id=UserModel.objects.get(user_id=user_id),
            serial_number=replace,
            file_path=file_path)
        file_model.save()
        base_response.result = {"file_id": file_model.serial_number}
        base_response.error_code = 1
        base_response.error_msg = 'upload image success'
    return HttpResponse(jsonTool.object_to_json(base_response),
                        "application/json")
Example #8
0
def get_apk_list(request):
    BaseResponse = BR()
    if request.method == 'GET':
        user_id = request.GET.get("userId")
        plugin_id = request.GET.get("pluginId")
        if user_id is None or user_id == '':
            BaseResponse.error_msg = 'user id can not be empty'
            return HttpResponse(jsonTool.object_to_json(BaseResponse),
                                "application/json")
        if plugin_id is None or plugin_id == '':
            BaseResponse.error_msg = 'plugin id can not be empty'
            return HttpResponse(jsonTool.object_to_json(BaseResponse),
                                "application/json")
        apk_file_model = ApkFileModel.objects.values(
            "plugin_id", "apk_id", "apk_name", "apk_description", "apk_url",
            "apk_path", "package_name", "version_code", "version_name",
            "min_sdk_version", "target_sdk_version", "file_path").filter(
                plugin_id=PluginModel.objects.get(plugin_id=plugin_id))
        BaseResponse.error_code = 1
        BaseResponse.result = {"list": list(apk_file_model)}
        BaseResponse.error_msg = 'request success'
    return HttpResponse(jsonTool.object_to_json(BaseResponse),
                        "application/json")