Jump to content

Restricting access to whole site


Jonathan Dart
 Share

Recommended Posts

I just tried to remove the guest view page privilege from the homepage template and got the following message:

"TEMPLATE 'HOME' IS USED BY THE HOMEPAGE AND THUS MUST HAVE THE 'GUEST' ROLE ASSIGNED."

As a work around I thought I'd create a subpage of the homepage called "restricted" or something like that and put all other pages under that. Is there a better way to accomplish this?

Link to comment
Share on other sites

Welcome to the forums Jonathan Dart :)

Without guest role your site is not viewable :) I believe

Maybe if you could explain what exactly you are trying to accomplish? If you don't create any other users, i.e. leave only the defaults (superuser [you] and guest [can only view]), then you have nothing to worry about. Maybe am not getting you :D

Edit: 

I knew I was not getting you.having read Apeisa's post below...I am kinda slow that way ;):D

Edited by kongondo
Link to comment
Share on other sites

I think there are some reason for not being able to restrict guests from home.. maybe PW is just polite for guests?

One way to do that kind of check is in template code, and best way there is in prependTemplate (if you use pretty recent version of PW).

Just uncomment this line: https://github.com/ryancramerdesign/ProcessWire/blob/master/site-default/config.php#L58 and add file called _init.php into your templates folder. Add this snippet there:

<?php

if ( ! $user->isLoggedIn()) {
  echo "Sorry dude";
  die(); // or redirect to somewhere and check that "not available page" on that if above
}
  • Like 1
Link to comment
Share on other sites

I rolled my own "maintenance mode" by adding a preferences page with a maintenance_mode checkbox and a RTE field called maintenance_mode_message to display to the user if they're not logged in. I then added the following code snippet to the top of my header include which is included in all my template files:
<? 
if($pages->get('name=preferences')->maintenance_mode && !$user->isLoggedin()) { 
    echo $pages->get('name=preferences')->maintenance_mode_message;
    exit;
}    
?>
 
If the conditions are met (user is not logged in and maintenance_mode checkbox is checked), the user will only see the contents of maintenance_mode_message and will not be able to view the site.
Link to comment
Share on other sites

Thanks for the feedback guys, this was a can of worms situation. I came to realize I also needed a frontend login form and I leveraged the homepage being viewable by all to accomplish this. I wanted to to have csrf protection in my form so I extended the ProcessLogin core module (https://gist.github.com/jdart/6545755) and called the module in the home template: 

#home.php
echo $modules->get('SpexLogin')->execute();
if (!$user->isLoggedin()) return;

Hopefully that will be helpful for someone.

 
Maybe 
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...