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.]