2

I found this post about restricting an entire asset source and placing it below the root level: Is it possible to have secure (private) assets?

What I'd really like to do is be able to set the members-only restriction on a per-file basis, perhaps with a lightswitch field.

The imagined flow would be:

  • user clicks a file link (anywhere, or even has a direct URL to the file)
  • .htaccess sends all .pdf, .doc, etc requests to a download checker page
  • download checker page sees if the requested file has the lightswitch checked
  • if no, download the file
  • if yes,
    • if logged in, download the file
    • if not logged in, show the registration / login page
      • upon login or registration, start the file download

I'm still relatively new to Craft and have the feeling there may be specific twig/craft abilities that make this — or something very similar — simple. I don't necessarily need the code handed to me, just some ideas about what tools are available to help with this process.

2

Why don't you just set up two separate asset sources, one default one with files being freely accessible and one source with access for logged-in users only by making use of that Internal Assets Plugin you mentioned.

Instead of managing the rights with a lightswitch you would upload or move the assets in the right source.

Another option would be to have two asset fields for your entry type, one configured for each source. And you could then always hide one of them with a lightswitch using the brand new Reasons plugin.

  • Oh cool, new-to-me feature discovery: drag 'n' drop assets to different asset sources and Craft moves the file(s). Nice. This plus the plugin mentioned in the linked thread for private sources may do the trick, thanks! – Kirk Roberts May 26 '15 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.