getgrav / grav-plugin-login

Grav Login Plugin
http://getgrav.org
MIT License
44 stars 54 forks source link

How to make a page accessible only for unregistered users? #179

Closed lufog closed 5 years ago

lufog commented 6 years ago

I want to hide login, register, forgot and reset pages from registered users. I search info about this but do not found nothing.

rhukster commented 6 years ago

Is this specific to multilanguage?

lufog commented 6 years ago

Yes, I'm planning a multilingual site, but I do not see the connection with the question. I created my own login and registration pages, created templates for them. image The problem is that these pages are available for authorized users. Now I solved this problem using a template, checking whether the user is logged on. image But it seems to me that this is a bad decision, and it does not look very good... I want to try to hide these pages using header: access:

I hope that I clearly explained, and sorry for the typos, English - not my native language.

rhukster commented 6 years ago

On this registration page try putting this:

login:
    visibility_requires_access: true

It won't stop access, but will make it 'invisible' to any navigation, or you could at least check page.visible

lufog commented 6 years ago

Thank you for such a quick response. I successfully hide them from the menu) I would like to protect them from direct access by reference. After all, it's strange when an authorized user can open the registration page.

rhukster commented 6 years ago

What would you do? show a 404? redirect to another page? It's kinda hard to know what your workflow would be in this case.. You can just put a message, saying "already registered" if they are logged in and not show the form.

lufog commented 5 years ago

Yeap, I need ability to redirect authorized user to home page.

rhukster commented 5 years ago

I think the best thing to do is to achieve this in Twig with this code:

{% if grav.user.exists %}
   {% do grav.redirect('/') %}
{% endif %}

This will redirect to the root of the site.. or you could put a /not-found url so you get a 404. However for this to work best you should add this to the 'register' page twig.

I've modified the login plugin (soon to be released) to provide a base register.html.twig template (that simply extends form.html.twig) that you can override in your theme with this check/redirect logic.