Sidebar logout button

Creating and modifying plugins.
Post Reply
Culky
Regular
Posts: 5
Joined: Fri Sep 17, 2004 10:10 am

Sidebar logout button

Post by Culky » Fri Sep 17, 2004 10:34 am

I'm making a simple plugin to put the username/password textboxes on the sidebar, or links to create a new entry / go to the admin page / logout if you're already logged in.
It's all working fine except I can't find a nice way to perform the logout. It works if you do the same link as in the admin page:

Code: Select all

serendipity_entries.php?serendipity[adminModule]=logout


but I don't want it to take you to the login page, I just want it to reload the default page, but with the user logged out.
I can do a "serendipity[action]=logout" and catch that within the plugin, and then do a "serendipity_logout()":

Code: Select all

if (isset($serendipity['GET']['action']) && $serendipity['GET']['action'] == 'logout') serendipity_logout();

if (serendipity_userLoggedIn()){
echo '<a href="?serendipity[action]=logout">Logout</a></div>';
} // else draw username / password boxes


but obviously anything processed before the plugin still considers you to be logged in. I'm hoping to do it without an edit to any other file, just because that would miss the point of having a plugin.
I'm new to php (although not to programming) so forgive me if I've missed something obvious.

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sidebar logout button

Post by garvinhicking » Fri Sep 17, 2004 2:57 pm

One thing comes to my mind:

1. Create an event plugin like 'serendipity_event_logout'.

2. Make use of the 'external_plugin' event hook for that plugin. See the blogpdf or lovesearch plugin, for how they do it.

3. Create a hook so that calling http://yourblog/serendipity/plugin/logout (see $methods / $parts variable in the blog-pdf module, you will need a 'logout' part case in the switch statement)

4. That hook/method will then call serendipity_logout and after that, use a header('Location: ' . $_SERVER['HTTP_REFERER']); call to redirect you to the page were you were coming from.

5. Now edit your sidebar plugin code and let the link to logout just target to
http://yourblog/serendipity/plugin/logout - you can click on it, and then you will be redirected to the originating page as a logged-out user.

Since you seem to be pretty eager, I'd trust you to make all things work. And maybe we can then recruit you as a cool plugin creator. Just ask for help here, if you have any further questions. :-)

Best regards,
Garvin.
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

Culky
Regular
Posts: 5
Joined: Fri Sep 17, 2004 10:10 am

Post by Culky » Fri Sep 17, 2004 11:15 pm

Brilliant! That works perfectly. Norton and I think some other firewalls tend to kill the HTTP_REFERER but I'm just sending it back to the index page if it's not set.
The plugin dependecies are handy for making sure both the plugins load, too.
I'm still a bit unsure about the right way to construct the urls for the "Create new entry" and "admin" links. They work, but I doubt they're very fool-proof or portable. So far I've got:

Code: Select all

$newEntryLink = $serendipity['baseURL'] . 'serendipity_entries.php?serendipity[adminModule]=entries&serendipity[adminAction]=new';


and

Code: Select all

$adminLink = $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? 'serendipity_entries.php?/' : '?/') . 'entries';


I don't really understand what the rewrite option does but those work on my local test server (rewriting disabled) and on my host (rewriting set to "apache errorhandling").

When I'm sure those are as they should be, I'll stick up a link to the plugin files in case anyone's interested.

Thanks for your help!

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Sat Sep 18, 2004 8:31 pm

Hi Culky!

Great that you got it working! :)

The two links are fine, you can use them. The "rewrite" part is just used, so that when a user does not use apache errorhandling for his blog, the url:

http://yourblog/entries

is not valid - in that case you'd need to request a valid, existing php file:

http://yourblog/index.php?/entries or
http://yourblog/serendipity_entries.php

So, in the end you could just use a straight link to 'serendipity_entries.php' - that's the same, where the redirection points to :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

Culky
Regular
Posts: 5
Joined: Fri Sep 17, 2004 10:10 am

Just for completeness

Post by Culky » Tue Sep 21, 2004 9:27 pm

I had to fix a couple of problems with inherited css styles and I'm sure there's a lot that could still be improved, but I've stuck these plugins in a zip for anyone who's interested:

http://www.risingdawn.org/plugins/serendipity_plugin_loginbox.zip

Off-topic, but while I'm thinking about it I did an alternative archives plugin which I've put in the same place.

http://www.risingdawn.org/plugins/serendipity_plugin_datelist.zip

Post Reply