Disable Gadgets to User if not logged in...

Cool tips and tricks about Jaws

Disable Gadgets to User if not logged in...

Postby hayden » Thu Oct 21, 2010 3:59 am

ok so maybe you just want users to be able to login before they can access particular gadgets or all of them, here's how i did it

:arrow: #1 Backup the file you are about to edit !!

editing include/Jaws/Layout.php function PutGadget starts in line 601

In the blank space at Line 604:(jaws version 0.8.14) insert:

Code: Select all
        //echo $gadget; //usefull to see what's being loaded, uncomment to echo/print
        $exempt_gadgets = array('Users');//array of gadget names exempt from login restrictions
        if( !in_array( $gadget,$exempt_gadgets) && !$GLOBALS['app']->Session->Logged()){//the test
        $enabled = 'false';//see final change at bottom of this function
        $deliberate = 'true';       
        }


so it looks like this:

Code: Select all
        if (Jaws_Error::isError($enabled)) {
            $enabled = 'false';
        }
        //echo $gadget; //usefull to see what's being loaded, uncomment to echo/print
        $exempt_gadgets = array('Users');//array of gadget names exempt from login restrictions
        if( !in_array( $gadget,$exempt_gadgets) && !$GLOBALS['app']->Session->Logged()){//the actual test
        $enabled = 'false';//see final change at bottom of this function
        $deliberate = 'true';       
        }
        $output = '';
        if ($enabled == 'true') {



then finally at the bottom of the function what was :!: line 653

change

Code: Select all
Jaws_Error::Fatal('Gadget ' . $gadget . ' is not enabled', __FILE__, __LINE__);


to
Code: Select all
if(!$deliberate)Jaws_Error::Fatal('Gadget ' . $gadget . ' is not enabled', __FILE__, __LINE__);
//prevent fatal error if weve disabled a gadget above due to no login
       



thats it :D , naturally you need 'Users' in the list of exempt gadgets, so users can login, maybe you just want it like that but if you want to also allow non-logged in access to StaticPage & Blocks for example. you need to edit the code line

Code: Select all
$exempt_gadgets = array('Users');//array of gadget names exempt from login restrictions


to

Code: Select all
$exempt_gadgets = array('Users','StaticPage','Blocks');//array of gadget names exempt from login restrictions
:geek:
hayden
 
Posts: 96
Joined: Wed Oct 22, 2008 12:17 pm
Location: Sydney, Australia

Return to Tips and Tricks

Who is online

Users browsing this forum: No registered users and 1 guest

cron