We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40045
    • 534 Posts
    I just installed the new extra QuickBar and wanted to add a Logout Button (as already existing but commented out in the chunk provided...seems the author also had problems with this one...) for convenience only...I mean...shouldn't be too difficult^^...I thought...I researched a bit and could not find anything but this thread and some other stuff about the Login snippet/package, so first I tried this one trying to call
    [[~[[*id]]? &service=logout]]
    (basically because I included the Login snippet with an empty template in the QuickBar chunk, just to have the logout functionality^^...what overkill, but I tried...) but that did not work, probably because the user (me and also other users) had logged in through the normal /manager login and not via the Login snippet, so I suggested that Login didn't know that I'm logged in, so it cannot log me out...(is that true, anybody?)

    so now...remove that Logout button again...naaah =)...packed my embarrassing php knowledge together and digged into the code of the Login snippet...

    found what I needed in core/components/login/controllers/Login.php there is a function called logout...and not a very difficult one...so I just pulled out some code and put together the following snippet:

    <?php
    /* snippet [[!Logout]]
     * does exactly that if you are logged into the manager and call a page with get param action=logout
     * usage [[~[[*id]]? &action=logout]] or however you want to create that link
     */
    
    if ( $_REQUEST['action'] = 'logout' ) {
    	$response = $modx->runProcessor('security/logout',array(
    		'login_context' => 'mgr'
    	));
    
    	if (!empty($response) && !$response->isError()) {
    		//$modx->log(modX::LOG_LEVEL_ERROR, 'Successfully logged out from frondend (hopefully)');
    	} else {
    		$modx->log(modX::LOG_LEVEL_ERROR, 'Logout failed!');
    	}
    }
    


    what I can do now (because this snippet is called within the chunk of QuickBar, which is only called when I'm logged into the manager) is what I wanted before, just put in
    [[~[[*id]]? &action=logout]]
    or call just some
    http://www.domain.tld/page.html?action=logout
    and without anything (not even a redirect...should I add that?) you are simply logged out of the manager...

    and that's how it looks:



    now my question...I just don't trust myself =P...do I open some really bad security hole with this or is this just ok to do it like that (which would be ok for me =P)? [ed. note: exside last edited this post 13 years, 10 months ago.]
      • 38290
      • 712 Posts
      I can assure you I did try and add login functionality when creating QuickBar but was unable too. I'm so glad you figured that out! I can assure you that, assuming it hasn't opened any bad security holes (which I don't think it has) that it will be integrated into a future release of QuickBar.
        jpdevries
        • 40045
        • 534 Posts
        @jpdevries:

        hey, first of all, great you found that thread (regarding it's in the evo forums) and thanks for the QuickBar, it's quite handy and doesn't insert a crapload of scripts and stuff like other frontend-extras!

        I made the snippet a bit more extendable and also inserted a button for clearing the cache from frontend:

        <?php
        /* snippet [[!Actions]]
         * usage [[~[[*id]]? &action=actionname]] or however you want to create that link
         *
         * @autor exside
         * @license free beer and do whatever you want with it license =)
         * @version 1.0
         * @modified 22.11.2012
         * 
         * @param GET
         */
        
        $action = $_GET['action'];
        //$modx->log(modX::LOG_LEVEL_ERROR, $action);
        switch( $action ) {
        	case 'logout': 
        		$response = $modx->runProcessor('security/logout',array(
        			'login_context' => 'mgr'
        		));
        
        		if (empty($response) && $response->isError()) {
        			$modx->log(modX::LOG_LEVEL_ERROR, 'Logout failed!');
        		}
        		break;
        	case 'clearcache':
        		$modx->cacheManager->refresh();
        		//$modx->log(modX::LOG_LEVEL_ERROR, 'Cache cleared');
        		break;
        }
        


        the chunk for QuickBar now looks like this (I also edited the css quite a lot, if you're interested i'll provide it to you...):

        <link rel="stylesheet" href="[[++base_url]]assets/components/quickbar/style.css">
        [[!Actions]]
        <div class="quickbar-wrapper">
        	<div class="quickbar">
        		<ul>
        			<li><a href="[[!getMgrURL]]?a=30&id=[[*id]]" target="_blank">Edit Resource</a></li>
        			<li><a href="[[!getMgrURL]]" target="_blank">Dashboard</a></li>
        			[[-<li><a href="[[!createNewLink]]" target="_blank">Create Here</a></li>]]
        			<li><a href="[[~[[*id]]? &action=clearcache]]">Clear Cache</a></li>
        			<li class="right"><a href="[[~[[*id]]? &action=logout]]">Logout</a></li>
        		</ul>
        	</div>
        </div>
        


        maybe another suggestion... I don't like it very much, when extras create new templates, especially simple ones like QuickBar, I mean it's mostly for documentation purposes...but now I have an unnecessary template there =)...so could you leave that out in the next version?

        keep it up! [ed. note: exside last edited this post 13 years, 10 months ago.]