We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4172
    • 5,888 Posts
    is it possible to run a snippet on a pdf-resource before outputting the pdf itself?

    This is the situation:
    A user gets a link in a email with a hash and his email in the url to a landing-page.
    There is a custom-table with his entry (email only)
    If the code was correct, they get a 'confirmed' in their SESSION and they get a link on that landing-page to a pdf-file (static resource)
    They are not registered as MODX-users, and I don't want to have them registered as MODX-users, so I can and do not want to work with resource-groups.

    I would like to run a snippet (with redirection) on the pdf-resource to deny access for users, which doesn't had a correct uri.
    I know, this would be possible with a plugin.
    But, if possible, I don't want to run a plugin on every request, which would run for every resource.

    Anyone did something like that?


    This question has been answered by Bruno17. See the first response.

    [ed. note: Bruno17 last edited this post 11 years, 10 months ago.]
      -------------------------------

      you can buy me a beer, if you like MIGX

      http://webcmsolutions.de/migx.html

      Thanks!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Static binary resources get all the way up to just before the final event, then they get sent back around to start over to set different HTTP headers. So BobRay's method should work, with a snippet in a template that the static resource is assigned to.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 4172
          • 5,888 Posts
          Thanks, Susan.

          This is, what I've had thought.
          But seems this doesn't work with static pdf-resources, while it is working with normal resources.

          Have this in the template:

          [[!redirect_unauth]]
          [[*content]]
          


          the pdf-resource is still accesible.



            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
          • discuss.answer
            • 4172
            • 5,888 Posts
            ok, seems there is no other way, than using a plugin 'OnWebPagePrerender' which does this:

            $parent = $modx->resource->get('parent');
            if ($parent == '31') {
                //protected ebook-resources are under parent 31
                $auth = isset($_SESSION['ebook_download_auth']) ? $_SESSION['ebook_download_auth'] : false; 
                if (!$auth){
                    $modx->sendUnauthorizedPage();
                }
            }
            


            which is a good way, I think
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!