No User album creation in embedded CMS

drumicube

Joined: 2005-01-07
Posts: 32
Posted: Mon, 2005-02-14 00:29

I have activate the User Album plugin.

Concerning the configuration:
the Create albums option is set to "When first accessed"
Jump to user album after login is checked.

When i log a new user from the CMS , no User album is visible.
It is only when I log from the G2 native interface than this new album is created.

Did i missed something ?

NOTE: The CMS is phpnuke, but is it reproductible with something else ?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-02-14 01:02

jump to user album after login will only happen via the G2 login view.. you're probably not using that for embedded.
look at the code in modules/core/UserLogin.inc where it creates a Gallery::Login event.. you can copy this code and put it in your embed setup if you like.. user album module will return the redirect parameters via this event when "jump to user album after login" is checked. pass the parameters to $urlGenerator->generateUrl to get the redirect url.
or you can simply redirect to g2_controller=useralbum:UserAlbum to hardcode this behavior.

 
drumicube

Joined: 2005-01-07
Posts: 32
Posted: Fri, 2005-02-18 13:03

OK ! Thanks to your help, i have tested it.
First, i can't put a redirection in my phpnuke module homepage:
This file is the entry point for G2 and is called everytime, without appropriate checks the redirection leads to an endless loop...
Second: This is a fully internal G2 process, so it seems to me it was better to integrate it in the embedded section of G2

So i tested this in embed.php


    /**
     * Ensure G2 session has same active user as CMS session.
     * No need to call directly if activeUserId is passed to init().
     *
     * @param string external user id of active user (null or empty for anonymous/guest user)
     * @return object GalleryStatus a status object
     * @private
     */
    function checkActiveUser($activeUserId) {
	global $gallery;
	$session =& $gallery->getSession();

	$idInSession = $session->get('embed.id.externalUser');
	if ($idInSession === $activeUserId) {
	    return GalleryStatus::success();
	}

	if (empty($activeUserId)) {
	    // Logout..
	    $ret = $session->reset();
	    if ($ret->isError()) {
		return $ret->wrap(__FILE__, __LINE__);
	    }
	    $session->put('embed.id.externalUser', '');
	} else {
	    // Set G2 active user..
	    list ($ret, $user) =
		GalleryCoreApi::loadEntityByExternalId($activeUserId, 'GalleryUser');
	    if ($ret->isError()) {
		return $ret->wrap(__FILE__, __LINE__);
	    }
	    $session->put('core.id.activeUser', $user->getId());
	    $session->put('embed.id.externalUser', $activeUserId);

		// -------------------- Login event Hacks (start here)--------------------------

	    $event = GalleryCoreApi::newEvent('Gallery::Login');
	    $event->setEntity($user);
	    list ($ret, $redirect) = GalleryCoreApi::postEvent($event);
	    if ($ret->isError()) 
	    {
			return array($ret->wrap(__FILE__, __LINE__), null);
	    }

	    // Redirect if requested by event listener, otherwise return
	    if (!empty($redirect)) 
	    {
			$results['redirect'] = array_shift($redirect);
			$urlGenerator =& $gallery->getUrlGenerator();
			$url = $urlGenerator->generateUrl($results['redirect']);
			header('Location: ' . str_replace('&', '&', $url));
	    }

		// -------------------- Login event Hacks (stop here)--------------------------
	}

It did the trick very well :D
The login redirect work nicely same for the album creation at login.
I think Valiant is the one in charge for embed.php, so please tell me if this is correct, and if this can help. Fell free to do what you want with this !
:wink:

The only annoying thing i have noticed, is the following:

1 - Login in phpnuke as a user
2 - Visit G2 pages.
3 - Logout in phpnuke
4 - Visit ONLY phpnuke related pages
5 - Relogin as the same user in phpnuke
6 - Return to G2 pages.
You are not redirected to the home user album !
This is because G2 was never noticed of a Login/Logout process.
This is not very dramatic, and i can't see how this can be fixed as G2 only received information from the CMS when you call it.

[EDIT]
Another point i have just noticed:
My gallery contains 3 users albums for the user drumicube, if i logged with the redirect active, it creates a drumicube_001 album and redirect to it !!!
This is only reproductible for this user, and this is the only one who have more than one personnal album.
My CVS update is rather old (more than one week) and i have 'played' a lot with the database during testing.
Stay tuned i will inform you after a fresh needed reinstall...

Cheers.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-02-18 15:32

1. Your code seems to a copy of modules/core/Userlogin.inc and function _GalleryMain_doRedirect from main.php. Only minor changes are needed to make it correct.
Specifically:
- add: return value array('isDone' => true); if you redirect
- checkActiveUser and init both have no return value but the status code. this has to be changed because you need to call done; and exit; if you do a redirect
- only raise the event, if appropriate
- you asked if it was correct: the only incorrect line is:
return array($ret->wrap(__FILE__, __LINE__), null);
ATM, this function only returns a status code, so
return $ret->wrap(__FILE__, __LINE__);
would have been correct, plus a return GalleryStatus::success(); at the end of the function

So, when do you need to raise the login event?
In xaraya, g2 gets notified (=synchronized G2 logout), if a user logs out from xaraya. So your code would work without changes for the xaraya integration.
But most CMS don't allow hooking some functionality into other functions (hooks, events). So, what do we do then? In this case, the user was never logged out in G2. Maybe we just shouldn't redirect to the user album, or redirect all G2 request to the user album, which don't specify another view/controller. Or you could modify the link in the CMS that points to G2 and make it point to the user album of the active User. Or ....

Another problem:
Consider the case when a user doesn't want to get redirected to his user album.
1. user logs in in CMS
2. user browses in CMS, clicks on a G2 imageblock image (not in G2) or user clicks on deep G2-link in CMS that points to a certain item/album
3. user gets redirected to his user album, because its the first visit of G2 after the CMS login. but actually, user wanted to see something different.

Solution:
a) only redirect to user album, if no other view is requested (i.e. if request url doesn't specify another contrller/view). but where should the code go?
or
b) only redirect to user album, if it was explicitely requested.

 
drumicube

Joined: 2005-01-07
Posts: 32
Posted: Sat, 2005-02-19 16:16

That what i thought when i was posting this... The number of particular case, the fact embed.php could be called from many different CMS etc...
I was asking myself, ahh... It is not so obvious !
But one thing is sure: For now the user album module is totally unsupported in phpnuke (there is even no user album creation)

In order to fix this , I will add an entry "Your User Album" in phpnuke who redirect corectly, this will be available only if the module if active of course...
I seems to be the more simple, no ?

If you decided to provide similar functions in your embed code, please keep me inform, i will adjust my module as quicky as possible.

And thanks for your tips, it always help me a lot !

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sat, 2005-02-19 16:32
drumicube wrote:
But one thing is sure: For now the user album module is totally unsupported in phpnuke (there is even no user album creation)

But it should work. At least it works in my xaraya integration. Activate the user album module. Create a new cms user and G2 will create a corresponding user album. See also Site Admin->General->User Album for additional features.

 
ophidite

Joined: 2004-03-26
Posts: 26
Posted: Sun, 2006-09-24 13:06

www.ophidite.com

Hello

Can you tell me which file i have to change to make it work in a Wordpress embedded environnement

Thanks in advance