On the fly user creation little problem

Slayergirl
Slayergirl's picture

Joined: 2007-09-12
Posts: 180
Posted: Wed, 2007-10-03 13:28

I use the on the fly user creation script from the documentation
$emAppUserId = "someone";
$ret = GalleryEmbed::init(array('embedUri' => $embedUri, 'g2Uri' => $g2Uri, 'activeUserId' => $emAppUserId));
if ($ret) {
/* Error! */
/* Did we get an error because the user doesn't exist in g2 yet? */
$ret2 = GalleryEmbed::isExternalIdMapped($emAppUserId, 'GalleryUser');
if ($ret2 && $ret2->getErrorCode() & ERROR_MISSING_OBJECT) {
/* The user does not exist in G2 yet. Create in now on-the-fly */
$ret = GalleryEmbed::createUser($emAppUserId, ('username' => $emAppUserId));
if ($ret) {
/* An error during user creation. Not good, print an error or do whatever is appropriate
* in your emApp when an error occurs */
print "An error occurred during the on-the-fly user creation <br>";
print $ret->getAsHtml();
exit;
}
} else {
/* The error we got wasn't due to a missing user, it was a real error */
if ($ret2) {
print "An error occurred while checking if a user already exists<br>";
print $ret2->getAsHtml();
}
print "An error occurred while trying to initialize G2<br>";
print $ret->getAsHtml();
exit;
}
}
/* At this point we know that either the user either existed already before or that it was just created
* proceed with the normal request to G2 */

Which works like a charm. Except when it's the first time you enter the page (when you are not yet created as user) it probably works but the user name is not displayed (display mode : username | guest). Then when you click on a pic or other link or refresg the page then it is displayed. Is it possible to get it right the first time?

I am working to add users to the right group directly and then it's a bit annoying if you have to click a link first to see the right permissions.

 
ozgreg
ozgreg's picture

Joined: 2003-10-18
Posts: 1378
Posted: Fri, 2007-10-05 01:35

Can I make a suggestion, firstly do not include a user when doing a first level init. Why because you can then do a test on is externally mapped and create the user on the fly.. After you checked if the user exists, do a GalleryEmbed::checkActiveUser which will log on the correct user after that, either that or do a GalleryEmbed::checkActiveUser after you created the user and log in the new user then. You have better control doing the first level init without any users that way any errors are going to be fatal rather than mixing up error returns with missing users as well..

Also remember to finish off your second level init GalleryEmbed::handleRequest();

____________________________________
Wordpress / Gallery2 (WPG2) Plugin, WPG2 Downloads, WPG2 Documentation

 
Slayergirl
Slayergirl's picture

Joined: 2007-09-12
Posts: 180
Posted: Fri, 2007-10-12 06:46

thnx for the info I am going to try it later! :)