Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Securing a Generated PDF? #5

Open
danleecreates opened this issue Nov 13, 2019 · 4 comments
Open

Securing a Generated PDF? #5

danleecreates opened this issue Nov 13, 2019 · 4 comments
Labels
feature request New feature or request

Comments

@danleecreates
Copy link

Hi

Recently purchased Digital Download.

I'm wanting to secure a PDF download generated by another plugin called Enupal Snapshot. How would I do that with the Digital Download plugin and the following code which generates the PDF on the fly?

{% set downloadURL = craft.enupalsnapshot.displayTemplate("reports/pdf-report", settings) %}

<a href="{{ downloadURL }}">
        Download Report
</a>
@lindseydiloreto
Copy link
Contributor

Hi @nearkingdom, sorry for the late reply.

The way Digital Download is currently architected, you can only create a link (or token) for an Asset. The generated PDF from Enupal Snapshot isn't an Asset, it's just a regular file.

I've considered allowing the plugin to just accept any file for download, but of course there are challenges associated with that. In the short term, unfortunately, it simply can't be used with dynamically generated files.

I'll consider this a feature request to add the ability to specify a non-asset file path.

@lindseydiloreto lindseydiloreto added the feature request New feature or request label Nov 19, 2019
@lindseydiloreto
Copy link
Contributor

lindseydiloreto commented Nov 19, 2019

I stand corrected, Enupal Snapshot does generate an Asset!

https://enupal.com/craft-plugins/enupal-snapshot/docs/advanced/return-asset-model

If you have access to the Asset model, then you should be able to create a link or token normally.

Let me know if that does the trick for you!

@danleecreates
Copy link
Author

I have tried to integrate this with the Enupal Snapshot plugin but am getting an error.

Impossible to invoke a method ("getPath") on a string variable ("Something went wrong when creating the PDF file, please check your logs").

Here is the code

{% set pdfName = 'now'|date('Y-m-d') ~ '-' ~ date().timestamp ~ '-evaluation-' ~ companyName ~ '-' ~ firstName ~ '-' ~ lastName ~ '-' ~ submissionId ~ random(50, 500) ~ '.pdf' %}
                            {% set assetFolderRef = evaluationSettings.evaluationAssetRef %}
                            {%
                                set settings = {
                                    filename: pdfName,
                                    inline: false,
                                    overrideFile: true,
                                    asModel: true,
                                    singleUploadLocationSource: assetFolderRef,
                                    cliOptions: {
                                        'header-html': 'evaluation-tools/evaluation/pdf-header',
                                        'footer-html': 'evaluation-tools/evaluation/pdf-footer',
                                        'orientation': 'Portrait',
                                        'page-size': 'A4',
                                        'title': 'Evaluation for ' ~ companyName,
                                    },
                                    variables: {
                                        passSubmissionId: submissionId,
                                    }
                                }
                            %}

                            {% set assetModel = craft.enupalsnapshot.displayTemplate("evaluation-tools/evaluation/pdf-report", settings) %}
                            {% set filePath = assetModel.getPath() %}
                            {% set token = craft.digitalDownload.createToken(filePath, options) %}
                            <a href="{{ craft.digitalDownload.url(token) }}" class="f6 link white bg-animate bg-teal hover-bg-white hover-teal br-pill bn w-auto ph4 pv3 tc b pointer mb3">
                                <i class="fas fa-file-download"></i> Download Report
                            </a>

@lindseydiloreto
Copy link
Contributor

Don't pass in the file path, pass in the asset itself...

{% set token = craft.digitalDownload.createToken(assetModel, options) %}

Ω 2019-12-03 at 12 22 51 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants