Any advice on fixing my "loginRedirect" error?

spit

Joined: 2007-08-20
Posts: 14
Posted: Mon, 2007-08-20 17:04

My problem: I can't get "loginRedirect" to redirect to the page I want.

Detail:
a) I'm creating a website inside which you can access G2 using the embed feature
b) I've got it working from this post by Valiant at http://gallery.menalto.com/node/64956
c) currently AFTER successfully logging in I can get users to be redirected to their page (using useralbums module) or to the main G2 page (using the default)

What I want to achieve:
For users to be redirected to a different page outside G2 but on my server.

The code I currently have is exactly as Valiant suggested (it works like a dream in terms of embedding, but I can't get any redirection working):

require_once(dirname(__FILE__) . '/../embed.php');
$ret = GalleryEmbed::init(array('fullInit' => true));
if ($ret) die($ret->getAsHtml());
global $gallery;
$uid = $gallery->getActiveUserId();

I believe I need to use something along the lines of the following but I can't get it to work:
$ret = GalleryEmbed::init(array('fullInit' => 'false', 'loginRedirect' => 'http://www.mysite.com/Gallery2/mypageiwant'));

Any help would be gratefully received.

Thanks,
Spit

 
spit

Joined: 2007-08-20
Posts: 14
Posted: Tue, 2007-08-21 10:27

I've since (partly) solved this and can now get "loginRedirect" working, however I misunderstood it's purpose. I thought it would redirect to a different page AFTER successful login, however all it does is redirect to a new login page BEFORE logging in.

Is there any way to be transferred to a different logged-IN page AFTER logging in?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2007-08-21 11:34

> Is there any way to be transferred to a different logged-IN page AFTER logging in?

yes. the useralbum module does that already. it redirects the user to his own user-album after login.

you can create your own g2 module to redirect anywhere you want.

sample code:

class MyLoginRedirectModule extends GalleryModule /* and GalleryEventListener */ {

    function MyLoginRedirectModule() {
	global $gallery;
	$this->setId('myloginredirect');
	$this->setName($gallery->i18n('Login URL redirection'));
	$this->setDescription($gallery->i18n('Redirect on successfull login'));
	$this->setVersion('0.7.0');
	$this->_templateVersion = 1;
	$this->setGroup('gallery', $gallery->i18n('Gallery'));
	$this->setCallbacks('registerEventListeners');
	$this->setRequiredCoreApi(array(7, 27));
	$this->setRequiredModuleApi(array(3, 6));
    }

    /**
     * @see GalleryModule::registerEventListeners
     */
    function registerEventListeners() {
	GalleryCoreApi::registerEventListener('Gallery::Login', new MyLoginRedirectModule());
    }

    /**
     * @see GalleryEventListener::handleEvent
     */
    function handleEvent($event) {
	$result = null;
	switch ($event->getEventName()) {
	case 'Gallery::Login':
            /* Here you can redirect to any G2 view / controller or to any URL (href param) */
	    $redirectUrlParams = array('view' => 'myloginredirect.MyPage');
	    break;
	}
	return array(null, $redirectUrlParams);
    }
}
?>

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
spit

Joined: 2007-08-20
Posts: 14
Posted: Tue, 2007-08-21 13:05

Valiant,

Thanks for the fast reply.

How would I enter my URL - would I replace the line:

Quote:
$redirectUrlParams = array('view' => 'myloginredirect.MyPage');

with something like:

Quote:
$redirectUrlParams = array('view' => 'http://www.mysite.com/mypageiwant');

I have also just found a previous post of yours that approaches this from a different angle: http://gallery.menalto.com/node/58797

Is there an advantage of one method over the other?

Thanks in advance.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2007-08-24 11:10
spit wrote:
Valiant,

Thanks for the fast reply.

How would I enter my URL - would I replace the line:

Quote:
$redirectUrlParams = array('view' => 'myloginredirect.MyPage');

with something like:

Quote:
$redirectUrlParams = array('view' => 'http://www.mysite.com/mypageiwant');

I have also just found a previous post of yours that approaches this from a different angle: http://gallery.menalto.com/node/58797

Is there an advantage of one method over the other?

Thanks in advance.

change the line to:
$redirectUrlParams = array('href' => 'http://www.mysite.com/mypageiwant');

'href' is for any URL. 'view' and 'controller' are for G2 views/controllers (Model View Controller pattern).

@other approach:
i already forgot about that. yes, that could work too.
the approaches are a bit different. the other approach has the advantage that you can put the login form anywhere on your site, it doesn't have to be in G2.
this approach here is an integrated solution, using the normal login form of G2.

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage