jorenvanhee / craft-template-guard

Password protect any page or entry in Craft CMS.
Other
5 stars 0 forks source link

Dynamic loginRoute: login URIs based on entry types URIs #1

Closed CaitlinWeb closed 2 years ago

CaitlinWeb commented 2 years ago

Thank you for creating this plugin! Made it very easy to password protect entries without the heavy lifting that should been required for adding a feature like this.

I'm now looking at a need for password protecting multiple entry types with different login routes. For example, we have loginRoute set to something like /private-pages/access to reflect the URI for entry type "Private Pages". I'd like to set it up for another entry type called "Other Pages" but have the login uri reflect those URIs instead, so it would be /other-pages/access for those entries.

Is this possible? Could there be the ability to make loginRoute dynamic based on the entry/entry type being protected?

Also it would probably make sense to allow the template setting to be dynamic as well. That would just be a nice-to-have, though.

jorenvanhee commented 2 years ago

Hi, I'm glad you're getting some use out of the plugin!

While it would be technically possible to add this feature, it would introduce some unnecessary complexity to the code base. I don't think this is something a lot of people would need, so I'm not comfortable adding it.

I do think it is possible to get what you want with some clever redirecting and templating. You could try something like this:

  1. Make use of a custom login template
  2. In that template, you have access to the ref url param. You could do some regex matching on that param and based on the result, redirect the user to an other login template.

Let me know in case it isn't clear, good luck!

CaitlinWeb commented 2 years ago

@jorenvanhee Good point, definitely don't want to introduce unneeded complexity. The solution you proposed makes a lot of sense, I'll try that! Thank you for the quick response 😄