Alright - I've read EMBEDDING and read a couple of posts on this - but I'm not getting it (and they pay me to live/eat PHP all day :P )
Anyhow - I found the following:
Quote:
the activeUserId parameter in the GalleryEmbed::init() call is not the G2 user id.
It's the id of the user in your CMS.
you have to map the $cmsUserId to the $g2User->getId() with GalleryEmbed::addExternalIdMap() for existing users.
For new G2 users, you can create the G2 user and map it to the cms userId in a single step with GalleryEmbed::createUser();
But I'm not following...
Here is what I'm doing. I have a single-sign-on Intranet that is authenticating via Kerberos and I'm doing some security checking with LDAP queries... That's minutae...
The part I'm having problems with is that I'm attempting to force a login as the admin user when I myself am logged in...
My code says:
// if anonymous user, set g2 activeUser to ''
if($_SESSION['userinfo']['samaccountname'] == 'rwyatt'){
this is where I'm having the problem... What goes here. If I am logged in (I verified that it is recognizing that I'm logged in) how can I then make Gallery2 display the admin options, etc... ? What would $uid = ? The admin g_id is 6 for my particular install... I've tried GalleryEmbed::addExternalIdMap('admin') and a whole host of other things... addExternalIdMap always gives me a "call to non-member function" - so I don't know what's up with that...
}
else $uid = '';
// initiate G2
$ret = GalleryEmbed::init(array('embedUri' => 'index.php?id=167',
'embedPath' => '/staff/',
'relativeG2Path' => '../modules/gallery2',
'loginRedirect' => 'index.php?id=167',
'activeUserId' => $uid));
if (!$ret->isSuccess()) {
$data['bodyHtml'] = $ret->getAsHtml();
return $data;
}
Based on the above... Any help or do you need more code?
EXTREME appreciation for your help in advance of receiving it! [/b]
Posts: 32509
A user has two IDs. The ID you use for users in your application (externalId) and the ID we use for users in G2 (entityId). They are not the same. But we map those IDs in a table, such that we know which G2 user corresponds to which user in your application.
The activeUserId is the externalId of the current user.
What's the unique identifier in your single sign on solution / user management? Does each user have an id, name, user data or just name + user data?
You should use the unique identifier as activeUserId. If there's no id, maybe just use the username, if the username is unique.
But...
Before you can call GalleryEmbed::init(array('activeUSerId' => 15)); // assume 15 is the id of the admin user in your application.
you have to map your admin user with G2's admin user, else G2 doesn't know which user to load when you tell it "activeUserId = 15".
So, before you use G2, you'll have to call GalleryEmbed::addExternalIdMapEntry($externalId, $entityId, 'GalleryUser');
$entityId is in this case the id of the admin user in G2. There's not just one admin user in G2 and no super admin. so i recommend mapping the first admin user the db returns.
// how to get the g2 id of the admin user
ist ($ret, $groupId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup');
if ($ret->isError()) {
print $ret->getAsHtml;
exit;
}
list ($ret, $users) = fetchUsersForGroup($groupId, 1);
if ($ret->isError()) {
print $ret->getAsHtml;
exit;
}
list ($adminUserEntityId, $adminUserObject) = each($users);
Posts: 5
valiant - thanks for the fast reply and indeed - I'm getting closer..
I'm going to post the whole function just to make sure I'm not missing something else...
I'm not sure if this is right - but before I could call any of the functions I had to do an initial init - and then do it again after I got the UID?
Anyhow - something still isn't right...
Things that are right: the database table g2_ExternalMapID gives me the following:
rwyatt GalleryUser 6
rwyatt is my externalId and 6 happens to be the first uid returned from what I pasted from you in the above.
Now - when I run the script I get:
Any thoughts on where I went wrong?
Posts: 32509
several things.
1. you call GallerEmbed::init before $uid is defined. do your ldap authentication before the init() call, set $uid accordingly and then call ::init
2. you don't have to add the externalid map entry on each request. this is like an account creation, just do it once. it creates a a database table row, G2 will know your mappings once you have called addexternalidmap.
3. call init only once per HTTP request
Posts: 5
Excellent - works great... Whew! Thanks!
Posts: 5
thanks a lot for this post
it was pretty much the last major item to get my embed finished
huge thanks to teh gallery crew - its the best image app out there in my opinion
these forums are a great resource as well
Posts: 5
thanks a lot for this post
it was pretty much the last major item to get my embed finished
huge thanks to teh gallery crew - its the best image app out there in my opinion
these forums are a great resource as well
Posts: 1
I don't know what the problem is, but when I do this, I always seem to get the error below, or another error,
saying pretty much the same thing. Whats going on with gallerycoreapi?
Fatal error: Undefined class name 'gallerycoreapi' in ..../modules/core/classes/GalleryEmbed.class on line 781
----- FIXED -------
For anyone else reading this, my problem was, I didn't have the init as the very first thing.
As soon as I did that (and a whole lot more things). It worked fine