You are viewing the PKP Support Forum | PKP Home Wiki

login hook?

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
The Public Knowledge Project Support Forum is moving to http://forum.pkp.sfu.ca

This forum will be maintained permanently as an archived historical resource, but all new questions should be added to the new forum. Questions will no longer be monitored on this old forum after March 30, 2015.

login hook?

Postby christo » Thu Sep 06, 2007 2:54 am


I have looked through the lists of available hooks, and im sure im just missing it; but what is the hook to register against the post successful login event.

I want to intercept a successful login attempt and forward the user to a specific page if one is specified.

Posts: 22
Joined: Mon Jan 09, 2006 12:04 am
Location: Grahamstown, South Africa

Re: login hook?

Postby asmecher » Thu Sep 06, 2007 8:50 am

Hi Christo,

There's no specific hook for that, but you can use Request::redirect hook to intercept the usual redirect on a successful login. You can check that Request::getRequestedOp == 'signIn' and $url in the hook call == Request::url(null, 'user'). If so, redirect to your own page (though you may have to do some nimble work with a static variable to make sure you don't end up recursively calling the hook through repeated calls to Request::redirect).

Alec Smecher
Public Knowledge Project Team
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm

Re: login hook?

Postby christo » Tue Sep 11, 2007 7:55 am

Silly me! I didnt notice this:
Code: Select all
        $source = Request::getUserVar('source');
   if (isset($source) && !empty($source)) {
      Request::redirectUrl(Request::getProtocol() . '://' . Request::getServerHost() . $source, false);

just adding ?source=/path/to/redirect/to to the url does the trick.

If anyone is interested; i used this code to add the correct redirect parameters to my login redirect:

Code: Select all
//first get the absolute url using the Request Object's url function:
$url = Request::url('journal','page','op','path');
//then i strip off all the stuff that the stuff from the front (this is later added back on by the redirector)
$url = ereg_replace(Request::getProtocol() . '://' . Request::getServerHost(),"",$url);
if (!Validation::isLoggedIn()) {   
        //and now we redirect them to the loging page with our ?source=$url appended to the querystring
   Request::redirect('user','login',null,null,array("source" => $url));

..hope that helps someone...
Posts: 22
Joined: Mon Jan 09, 2006 12:04 am
Location: Grahamstown, South Africa

Return to OJS Development

Who is online

Users browsing this forum: No registered users and 3 guests