Hi! Using the new Kirby 3, what is the simplest way to password-protect a page?
I’ve been reading here and there, but all info looks outdated regarding the new Kirby 3. And i can’t find any official cookbook/guide. The protection level doesn’t need to be high. Just to be simple to use; submit pass and voilá. Something simple in PHP?
Side note: I’ve read online about the Javascript solution. It looks OK, i guess, in terms of ease of use, but i don’t want any potential customer, with web development superpowers, to crack the password location and laugh at my expense
Oh, sweet! I didn’t know you could access Kirby 2 docs. BTW, i noticed most of the forum’s posts have broken links too, so now i get they probably direct to these old docs.
Looks easy, just by reading it. I’ll try it out later at the end of the day. Thanks!
I followed the authentication process of K2. It is not working, at this moment, but i’m also not sure how to track where it is wrong. Here are some things i did/noticed.
Logging out
I didn’t change the code except where i’m defining the route. Since i’ve learned the new syntax, i believe it should be like this:
The log out URL doesn’t seem to work… At least, i’m still logged in in Panel.
Protecting the page
I can’t protect the page with this code, it just lets me in, even logged out of Panel:
<?php if(!$site->user()) go('/') ?>
Logging in
The log in page doesn’t seem to work too. I don’t have any way to detect it too. I can’t get the form errors and i’m not able to test if it works since the blocked page is unblocked. I’m using this code in the controller:
Thanks for your help! I’m starting to see a light at the end of the tunnel, but it’s still not working.
Page protection + Log out URL
This part seems to be working by forcing a login on panel.
Logged out, i enter the protected page and i’m directed to the log in page
Go to panel URL to post a log in
Logged in, i enter the protected page and i’m able to view it
Log in controller
I think there’s still an error here, because the log in page is not working. Attempts to post, but there is no response or redirect. Any ideas? I’m searching the reference but i’m not understanding if the line of the request is well structured.
I’m currently trying to set up a password protected section for the site I’m working on, this thread has been a great help!
What’s bugging me is that when I enter a wrong password, I don’t get the error message as html above the form element, which I thought would happen through the <?php if ($error): ?> part of the code, but instead kirby opens the debug console which states “Invalid login”.
Is there any way to prevent this and instead i.e echo the message in an alert?
I’ve added a hard-coded mail address into my controller so the user would only have to enter their password on the login page, which is working fine:
also, could somebody point me in the right direction of storing the last visited page before the login redirect happens, so the user gets sent back to that page instead of the homepage?