GalleryEmbed::login or GalleryEmbed::checkActiveUser ar not Working !

rilou

Joined: 2007-09-21
Posts: 2
Posted: Thu, 2007-09-27 09:31

Hi,

I'm trying to login an existing user.
The user_id '27' is existing, the '28' is not.
But when I use 27 or 28, the GalleryEmbed::login($user_id); is always ok !!

It's the same when i tried to checkActive user,
I have the same result when i'm trying
$ret2 = GalleryEmbed::checkActiveUser('27');
or
$ret2 = GalleryEmbed::checkActiveUser('28');

If you can give me a little help, it would be wonderfull !
Thanks.

My code :

require_once('../embed.php');
$user_id = '27';

$ret = GalleryEmbed::init(array('embedUri' => '/main.php',
'g2Uri' => '/'
));
if ($ret) {

} else {

$ret2 = GalleryEmbed::login($user_id);
if($ret2){
echo 'no login '.$user_id;
}else{
echo 'login ok '.$user_id;
}
}

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2007-09-27 11:14

not sure if you have already realized that the user_id expected by GalleryEmbed functions is another user_id than g2's own user ids.
there are existing forum discussions about it and its documented at docs -> development -> embedding & integration.

also, you can learn more about the errors you get by printing them.
e.g.
$ret = GalleryEmbed::checkActiveUser(.....);
if ($ret) {
print $ret->getAsHtml();
}

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

 
rilou

Joined: 2007-09-21
Posts: 2
Posted: Thu, 2007-09-27 15:43

Thx for the answer Valiant,

You were right, i was thinking that the user_id expected by GalleryEmbed functions was the same than g2's own user ids.

I'm just starting a new PHP application, without existing user database .
But i dont really need to have 2 User database, i just want to be able to login/logout/create/ user existing in g2 from my application.

Please just take a look to my structure.

My Application and g2 are in the same directory : (/)

/index.php -- My Application
/main.php -- g2 Main page

I just need that a user can login in index.php with the embedded Fonction and be recognise as user actually loggued in main.php

On my index.php page, I tried to put a form with "main.php" in the action argument . It was working, but only when the user clicked on the submit button of course.

So I really want to understand how to use the Embed Function, to be able to do everything by php.

I download the sample_embedding_wrapper but i don't succeed to make it working.

I put the file at the same directory :
/g2_embed.php

$data = runGallery();

if (isset($data['bodyHtml'])) {
print <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
{$data['bodyHtml']}
</body>
</html>
EOF;
}

function runGallery() {

require_once('embed.php');

$data = array();

// $uid 27 is existing 28 is not
$uid = '27';

$ret = GalleryEmbed::init(array('embedUri' => 'g2_embed.php','embedPath' => '/','relativeG2Path' => '/main.php','activeUserId' => $uid));

if (!$ret->isSuccess()) {
$data['bodyHtml'] = "yes";
return $data;
}else{
$data['bodyHtml'] = "no";
return $data;

}

}

///End of the file

At the end, I tried a last solution to logg manually the user with :

$g_id= md5(uniqid(rand(), true));
$_SESSION['GALLERYSID'] = $g_id;
setcookie("GALLERYSID",$g_id,time()+86400);
$req="INSERT INTO g2_SessionMap (g_id,g_userId,g_remoteIdentifier,g_creationTimestamp,g_modificationTimestamp,g_data)
values ('".$g_id."','".$tab['g_id']."','".$g_remoteIdentifier."','".$g_creationTimestamp."','".$g_modificationTimestamp."','".$g_data."') ;";

I know it's bad, but when i go to the main.php page, i was unloggued !!!

Oh really, I don't know how to do ...
I read all the docs about embeding, that's why my answer is so late.

Can you please explain me a last time or give me a link with example indicating how to synchronise g2 with a little php application, because
all the example i found were all starting with :

require_once('embed.php');
$ret = GalleryEmbed::init(array( 'embedUri' => 'index.php','activeUserId' => $tab['g_id'])); ...

but nothing about the file (/g2_embed.php in my case) which enable the synchronisation...

Thanks for your time.

Rilou.

 
Slayergirl
Slayergirl's picture

Joined: 2007-09-12
Posts: 180
Posted: Fri, 2007-09-28 07:52

http://codex.gallery2.org/Gallery2:Embedding:Integration -> On the fly user creation. Just a note: You cannot add the same user as the one that's already in the DB under g2_users now. ActiveuserId does not need to be an integer I am using it as a string and that's working fine.
My code which is still a mess btw and I am using another wrapper I found somewhere.

<?php
$emAppUserId ='newuser';
$emAppGroup ='Fotobeheer';
$g2_Config['path'] = dirname(__FILE__) . '/';

$g2_Config['g2Uri'] = '/multisitedir2/';
$g2_Config['embedUri'] = '/multisitedir2/gallery2embedded.php';

//print_r($g2_Config);
require_once( $g2_Config['path'] . 'embed.php');
if (!headers_sent()) {
header('Content-Type: text/html; charset=UTF-8');
}

$ret = GalleryEmbed::init(array('g2Uri' => $g2_Config['g2Uri'],
'embedUri' => $g2_Config['embedUri'],
'fullInit' => 'false',
'apiVersion' => array(1,0),
'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, array('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;
}
$this->done();
}
/* 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 */

// handle the G2 request
$g2moddata = GalleryEmbed::handleRequest();
etc. etc.