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

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

Closed
lufog opened this issue Sep 11, 2018 · 7 comments
Closed

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

lufog opened this issue Sep 11, 2018 · 7 comments
Labels

Comments

@lufog
Copy link
Contributor

lufog commented Sep 11, 2018

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

@lufog lufog changed the title How to make a page accessible only to an unregistered user? How to make a page accessible only for unregistered users? Sep 11, 2018
@rhukster
Copy link
Member

Is this specific to multilanguage?

@lufog
Copy link
Contributor Author

lufog commented Sep 11, 2018

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
Copy link
Member

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
Copy link
Contributor Author

lufog commented Sep 11, 2018

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
Copy link
Member

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
Copy link
Contributor Author

lufog commented Nov 7, 2018

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

@rhukster
Copy link
Member

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.

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

No branches or pull requests

2 participants