Jump to content

ProcessTemplate Additions


Jim Yost
 Share

Recommended Posts

In your /site/config.php there is a setting in there called:

$config->loginPageID = 23; 

Change 23 to the ID of the page you want to be the login page.

If you want to use a given login page only in some instances, I believe you can also change that $config item at runtime. For example, you might put this in some main template for your site:

$config->loginPageID = $pages->get("/tools/login/")->id; 

I haven't tried this, so let me know if it doesn't work and I can find another way to do it or make it part of the template config as you suggested.

Link to comment
Share on other sites

Thanks Ryan,

I tried adding the $config->loginPageID = $pages->get("/it/login/")->id; to my controller and it didn't help. I was still re-directed to the /processwire/login/ I believe that PW redirects before it even gives control to the template or controller. I only want the /it/login/ to show for the /it/ branch of templates.

This isn't a big deal for now, I currently have /it/ guest accessible and it will redirect to /it/login/ if the user isn't logged in or /it/dashboard/ if the user is logged in.

-Jim

Link to comment
Share on other sites

If you need to support multiple login pages, it would have to be adjusted before the template code (autoload module, include from your config file, etc.). But if I were setting this up, I think the best way to go would be to change $config->loginPageID in your config file to be your own login page, and just have one of them. Then let the login page template decide what to show and what to do. ProcessWire doesn't actually redirect to a login page, instead it just replaces the page they don't have access to with the login page... at the same URL.  As a result, your template can still inspect what page was requested by looking at $_SERVER['REQUEST_URI'], or you could even load it:

<?php

$requestedPage = $pages->get($_SERVER['REQUEST_URI']); 

if($requestedPage->path == '/private-page/') { // our private page 
    echo $pages->get('/private-page/login/')->render(); 

} else if(strpos($requestedPage->path, '/processwire/') === 0) { // for any admin page
    echo $pages->get('/processwire/login/')->render(); 

} else { 
    // load some other login page or render it here
}

(In the above snippet, of your site is running off a subdirectory, like /mysite/, then you'll want to remove /mysite/ from the REQUEST_URI since ProcessWire won't recognize that as a path it manages.)

With the example you mentioned, I'm not sure that the above info even matters, but I wanted to post it here as a solution for supporting multiple login pages. In your case, it just sounds like your /it/ page template needs to check if the user is logged in and send them to one page or another depending on the state. So here's what might work in your /it/ page template:

<?php

if(!$user->hasRole("required_role_name")) {
    $session->redirect("./login/"); 

} else {
    $session->redirect("./dashboard/"); 
}

Replace "required_role_name" with the role you created needed to access the /dashboard/ page. If you only need to know that they are logged in, then you could replace that first line with this:

if(!$user->isLoggedin() { ...
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...