Users logging in

treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Tue, 2005-11-22 03:11

Is there a way so that when a user hits the main gallery page I can pass that page a session variable or something like that and it would log the user into the site right away without them having to login again? I'm trying to limit the gallery only to users that are registered to my site and once they login I only want them to have to do it one time. Please let me know the best way to do this.

Thank you for the help in advance.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-11-22 10:54

g2 works already like that.

like every other web application that remembers users that have logged in once, we're using http cookies.
pretty much all browsers have cookies enabled by default (IE, mozilla, firefox, opera, safari, .....).

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Tue, 2005-11-22 13:32

I'm saying if I set a cookie on a page other then the gallery login page what would I have to call the cookie and set the contents of the cookie to be so that the gallery would be able to read it and get the username and password from it so they wouldn't have to login again?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-11-22 14:38

do you want to integrate / embed g2 in your website?
use GalleryEmbed -> docs/EMBEDDING

and if you're shy from interfacing with G2, manipulate the cookie GALLERYSID

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Tue, 2005-11-22 15:12

For this part of the embed document:

require_once(dirname(__FILE__) . 'relative/path/to/gallery2/embed.php');
$ret = GalleryEmbed::init(array(
'embedUri' => {value}, embedPath => {value}, 'relativeG2Path' => {value},
'loginRedirect' => {value}, 'activeUserId' => {value}));
if ($ret->isError()) {
// $ret->getAsHtml() has error details..
exit;
}

$g2data = GalleryEmbed::handleRequest();
if ($g2data['isDone']) {
exit; // G2 has already sent output (redirect or binary data)
}

Where would that go? All I want this to do is when the user clicks on http://www.website/v-web/gallery2/main.php it gets the person's username. If I have a regular HTML form for users to login with at a page like http://www.website.com which posts to http://www.website.com/login.php what would I need to do on that page so that when the user clicks on http://www.website/v-web/gallery2/main.php it automatically logs them in. Please help as I'm a newbie with this stuff. Do I need to write a cookie or something, if so what would be the code to write the cookie and the correct cookie contents? Do I need to call my text fields in the HTML form anything special?

Thank you.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Tue, 2005-11-22 15:12

Also, for the {value} in the above post do I have to populate that with acutal information or will that get populated by itself?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-11-22 15:18

If i understand you correctly, you want that a user is automatically logged-in in G2, when the user logs-in / is logged-in in your website.
Correct?
That would be the normal GalleryEmbed scenario.

Obviously, your website has already a user and session management. Correct?
Since G2 has its own user and session management, you will have to tell G2 which userId of your website corresponds to which userId of G2.
This mapping is in a database table (externalIdMap).
You can add entries into this map with GalleryEmbed::addexternalIdMap.

Once mapped, you can call GalleryEmbed::init(array('activeUserId' => $userIdOfAUserInYourWebsite, ...));
and it will automatically resume an existing session or create a new one.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Tue, 2005-11-22 15:46

So if I have a session called $_SESSION['username'], how would I map that in the database. If I mapped that correctly in the database then once the user clicked on the gallery they would automatically be logged in correct? Thanks for your continued help. I really appreciate it.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-11-22 17:09

i'm moving this topic to the integrations forum.

i still don't know whether your website already has a user management (list of users etc) and session management (logging in etc).
using GalleryEmbed makes only sense if you want a single-sign-on solution, that is, users only have to login into your website, and then they are automatically also authenticated / logged-in in G2.

you should look
a) at the sample wrapper attached to the sticky "Embedding and Integraitons" topic, first post
b) Existing integrations, wp, joomla, phpbb, ...

once the users are mapped in the database, you'd call
$userId = $_SESSION['username'];
// set $userId = '' if the user is not logged in into your website
if (...) {
$userId = '';
}
GalleryEmbed::init(array('activeUserId' => $userId));
GalleryEmbed::handleRequest();
... (see sample wrapper)

But how do you map users of your website with G2?
- when a user is created in your website, call GalleryEmbed::createUser() to create a corresponding user in g2. it automatically maps the two users.
- but what about existing users of your website and g2, they are not already mapped!
you have to manually map these users.
look at the database table g2_User. i guess you have a similar table for your website.
now you must enter for each pair of corresponding users a row in g2_ExternalIdMap (externalId = id of the user in your application. if you don't have ids, use the username from your application), entityId = g_id of the user from the g2_User table. entityType should be "GalleryUser".

if you don't want / can't call GalleryEmbed::createUser when a user is created in your application, you can do a "on-the-fly" user creation.
that is, when you call GalleryEmbed::init()... you should check the returned error, and if it's a ERROR_MISSING_OBJECT, you have to call createUser and then you can proceed with the request.

the existing integrations follow the same concept.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Tue, 2005-11-22 17:56

Ok, when a user logs i on the page login.html they enter in their username and password and then submit that page to logincheck.php. On this page I do $_SESSION['username'] = $_POST['username']. That is the start of the session for the user. This is also how I manage all the users on the site and what they can access on other pages. I took a look at the sample wrapper and not sure what to do with it. If I use your above code to make it:

$userId = $_SESSION['username'];
// set $userId = '' if the user is not logged in into your website
if (!isset($_SESSION[username])) {
$userId = '';
}
GalleryEmbed::init(array('activeUserId' => $userId));
GalleryEmbed::handleRequest();

Would that code go in the logincheck.php page as long as I have require_once("embed.php") on the page? I believe that is how that should go. Once they click on the http://www.website.com/v-web/gallery2/ it would then check to see if that userid was active and would either have the user login or already display the gallery to them as if they were logged in, correct?

Thaks fo rthe continued help.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-11-22 19:05

ok, so for anonymous users, the $_SESSION['username'] is not set. thus you first have to do the isset check, else you get a php warning / error.
$userId = '';
if (isset($_SESSION['username'])) {
$userId = $_SESSION['username'];
}
of course you need to init the sessionbefore you do that.

don't forget the other params to ::init (embedUri, ...)

no, the whole code would not go into your login code. the wrapper is the new entry point of g2.
you'd link to the wrapper instead of to main.php of g2.

please take a look at the phpbb integration or so.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Tue, 2005-11-22 19:58

Ok, I think I'm close. This is the code for login.html:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="loginconfirm.php" method="post">
<p>
<input type="text" name="username">
</p>
<p>
<input type="text" name="password">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

The code for loginconfirm.php:
<?
session_start();

$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];

echo "You logged in<br><br>";

echo "<a href=\"main.php\">Gallery</a>";
?>

Then the code for the wrapper main.php:
<?php

/*
* This is an example of how G2 can be wrapped into your own website
* If you only want to embed G2 visually in your website, you don't need GalleryEmbed (so this
* approach is not necessarily what you want). But if you want to embed G2 in your website,
* including a unified user management, a single login etc., then this is the correct file to
* start with.
*/

/*
* runGallery() exits if G2 tells it to so (by isDone = true). It's important that you don't
* output any html / anything before you call runGallery (which calls
* GalleryEmbed::handleRequest), else, G2 won't work correctly.
* Reason: G2 does a lot of redirects. E.g. when you login, it redirects to the next page, etc.
* and redirects won't work if there was already some output before the redirect call.
*/
$userId = '';
if (isset($_SESSION['username'])) {
$userId = $_SESSION['username'];
}

$data = runGallery();
$data['title'] = (isset($data['title']) && !empty($data['title'])) ? $data['title'] : 'Gallery';

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>{$data['title']}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
{$data['javascript']}
{$data['css']}
</head>

<body>
{$data['bodyHtml']}
</body>
</html>
EOF;
}

function runGallery() {

require_once('http://www.website.com/v-web/gallery2/embed.php');

$data = array();

// if anonymous user, set g2 activeUser to ''
$uid = '';

// initiate G2
$ret = GalleryEmbed::init(array('embedUri' => 'main.php',
'embedPath' => '/',
'relativeG2Path' => './gallery2',
'loginRedirect' => 'index.php',
'activeUserId' => $uid));
if (!$ret->isSuccess()) {
$data['bodyHtml'] = $ret->getAsHtml();
return $data;
}

// user interface: you could disable sidebar in G2 and get it as separate HTML to put it into a block
// GalleryCapabilities::set('showSidebarBlocks', false);

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

// show error message if isDone is not defined
if (!isset($g2moddata['isDone'])) {
$data['bodyHtml'] = 'isDone is not defined, something very bad must have happened.';
return $data;
}
// exit if it was an immediate view / request (G2 already outputted some data)
if ($g2moddata['isDone']) {
exit;
}

// put the body html from G2 into the xaraya template
$data['bodyHtml'] = isset($g2moddata['bodyHtml']) ? $g2moddata['bodyHtml'] : '';

// get the page title, javascript and css links from the <head> html from G2
$title = ''; $javascript = array(); $css = array();

if (isset($g2moddata['headHtml'])) {
list($data['title'], $css, $javascript) = GalleryEmbed::parseHead($g2moddata['headHtml']);
$data['headHtml'] = $g2moddata['headHtml'];
}

/* Add G2 javascript */
if (!empty($javascript)) {
foreach ($javascript as $script) {
$data['javascript'] .= "\n".$script;
}
}

/* Add G2 css */
if (!empty($css)) {
foreach ($css as $style) {
$data['css'] .= "\n".$style;
}
}

// sidebar block
if (isset($g2moddata['sidebarBlocksHtml']) && !empty($g2moddata['sidebarBlocksHtml'])) {
$data['sidebarHtml'] = $g2moddata['sidebarBlocksHtml'];
}

return $data;
}

?>

When I click on the link from loginconfirm.php I get the following error:
Fatal error: Undefined class name 'galleryembed' in /home/web/.panel/web/gallery2/test/main.php on line 55

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-11-22 20:31

require_once('http://www.website.com/v-web/gallery2/embed.php'); ??

use a server absolute path and not a url

set error_reporting(E_ALL); at the beginning.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Tue, 2005-11-22 20:58

I got it to display so I thank you for that, however the CSS doesn't load and any of the images don't load either. Do I need to change anything else. I put those files in the root of the folder gallery2 so this is what it looks like now:

<?php

/*
* This is an example of how G2 can be wrapped into your own website
* If you only want to embed G2 visually in your website, you don't need GalleryEmbed (so this
* approach is not necessarily what you want). But if you want to embed G2 in your website,
* including a unified user management, a single login etc., then this is the correct file to
* start with.
*/

/*
* runGallery() exits if G2 tells it to so (by isDone = true). It's important that you don't
* output any html / anything before you call runGallery (which calls
* GalleryEmbed::handleRequest), else, G2 won't work correctly.
* Reason: G2 does a lot of redirects. E.g. when you login, it redirects to the next page, etc.
* and redirects won't work if there was already some output before the redirect call.
*/
$userId = '';
if (isset($_SESSION['username'])) {
$userId = $_SESSION['username'];
}

//set error_reporting(E_ALL);
$data = runGallery();
$data['title'] = (isset($data['title']) && !empty($data['title'])) ? $data['title'] : 'Gallery';

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>{$data['title']}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
{$data['javascript']}
{$data['css']}
</head>

<body>
{$data['bodyHtml']}
</body>
</html>
EOF;
}

function runGallery() {

require_once('embed.php');

$data = array();

// if anonymous user, set g2 activeUser to ''
$uid = '';

// initiate G2
$ret = GalleryEmbed::init(array('embedUri' => 'main.php',
'embedPath' => '/',
'relativeG2Path' => '',
'loginRedirect' => 'index.php',
'activeUserId' => $uid));
if (!$ret->isSuccess()) {
$data['bodyHtml'] = $ret->getAsHtml();
return $data;
}

// user interface: you could disable sidebar in G2 and get it as separate HTML to put it into a block
// GalleryCapabilities::set('showSidebarBlocks', false);

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

// show error message if isDone is not defined
if (!isset($g2moddata['isDone'])) {
$data['bodyHtml'] = 'isDone is not defined, something very bad must have happened.';
return $data;
}
// exit if it was an immediate view / request (G2 already outputted some data)
if ($g2moddata['isDone']) {
exit;
}

// put the body html from G2 into the xaraya template
$data['bodyHtml'] = isset($g2moddata['bodyHtml']) ? $g2moddata['bodyHtml'] : '';

// get the page title, javascript and css links from the <head> html from G2
$title = ''; $javascript = array(); $css = array();

if (isset($g2moddata['headHtml'])) {
list($data['title'], $css, $javascript) = GalleryEmbed::parseHead($g2moddata['headHtml']);
$data['headHtml'] = $g2moddata['headHtml'];
}

/* Add G2 javascript */
if (!empty($javascript)) {
foreach ($javascript as $script) {
$data['javascript'] .= "\n".$script;
}
}

/* Add G2 css */
if (!empty($css)) {
foreach ($css as $style) {
$data['css'] .= "\n".$style;
}
}

// sidebar block
if (isset($g2moddata['sidebarBlocksHtml']) && !empty($g2moddata['sidebarBlocksHtml'])) {
$data['sidebarHtml'] = $g2moddata['sidebarBlocksHtml'];
}

return $data;
}

?>

Not sure if you have to do something to get the right CSS and images??

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-11-22 22:27

if you're using the rewrite module, deactivate it.

else: probably your embedPath / relativeG2Path, embedUri are wrong if it still doesn't work.

some examples are in docs/EMBEDDING

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Tue, 2005-11-22 22:56

Ok, I got it to work that it doesn't allow a user to login. I have two more questions.

1) How do I change the background color with that?
2) I logged in with my admin username and password setting that as my session. When I got to the gallery it doesn't give me the option to login but it also doesn't have the site admin, account settings etc, how do I get that to work?

Also there is no where on the bottom where it says display mode username | guest after logging in isn't there either.

Thank you for your continued help. This has been great.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-11-22 23:24

1) themes/matrix/theme.css or use a colorpack in g2 -> site admin -> themes -> matrix
2) map your admin user to the g2 admin user (insert row in externalIdMap) and then delete the db cache in gallery2/lib/support/ -> cache

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Tue, 2005-11-22 23:55

Do I have to map every user? Also what would be the way to insert it into to map a user with the username admin to the g2admin?

Since the fields in the database are g2_externalId, g2_entityType, g2_entityId what would I need to put for each of these for a regular user and the site admin?

Thanks

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-23 00:22

as i explained in a previous post in this topic:
yes, every user needs to be mapped.
and use the g_id of the g2_User table as entityId and the user id or username from your application as externalId and set entityType to GalleryUser.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Wed, 2005-11-23 00:42

It works! Thank you very much!

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Wed, 2005-11-23 02:39

I have the code:
<?php
session_start();
/*
* This is an example of how G2 can be wrapped into your own website
* If you only want to embed G2 visually in your website, you don't need GalleryEmbed (so this
* approach is not necessarily what you want). But if you want to embed G2 in your website,
* including a unified user management, a single login etc., then this is the correct file to
* start with.
*/

/*
* runGallery() exits if G2 tells it to so (by isDone = true). It's important that you don't
* output any html / anything before you call runGallery (which calls
* GalleryEmbed::handleRequest), else, G2 won't work correctly.
* Reason: G2 does a lot of redirects. E.g. when you login, it redirects to the next page, etc.
* and redirects won't work if there was already some output before the redirect call.
*/

//set error_reporting(E_ALL);
$data = runGallery();
$data['title'] = (isset($data['title']) && !empty($data['title'])) ? $data['title'] : 'Gallery';

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>{$data['title']}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
{$data['javascript']}
{$data['css']}
</head>

<body>
{$data['bodyHtml']}
</body>
</html>
EOF;
}

function runGallery() {

require_once('embed.php');
echo $userId;
$data = array();

// if anonymous user, set g2 activeUser to ''
$uid = '';
//$userId = '';
if (isset($_SESSION['username'])) {
$uid = $_SESSION['username'];

}
//echo "The username is: $uid";
//GalleryEmbed::createUser()

// initiate G2
$ret = GalleryEmbed::init(array('embedUri' => 'main2.php',
'embedPath' => '../v-web/gallery2/',
'relativeG2Path' => '../gallery2/',
'loginRedirect' => 'index.php',
'activeUserId' => $uid));
if (!$ret->isSuccess()) {
$data['bodyHtml'] = $ret->getAsHtml();
return $data;
}

// user interface: you could disable sidebar in G2 and get it as separate HTML to put it into a block
// GalleryCapabilities::set('showSidebarBlocks', false);

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

// show error message if isDone is not defined
if (!isset($g2moddata['isDone'])) {
$data['bodyHtml'] = 'isDone is not defined, something very bad must have happened.';
return $data;
}
// exit if it was an immediate view / request (G2 already outputted some data)
if ($g2moddata['isDone']) {
exit;
}

// put the body html from G2 into the xaraya template
$data['bodyHtml'] = isset($g2moddata['bodyHtml']) ? $g2moddata['bodyHtml'] : '';

// get the page title, javascript and css links from the <head> html from G2
$title = ''; $javascript = array(); $css = array();

if (isset($g2moddata['headHtml'])) {
list($data['title'], $css, $javascript) = GalleryEmbed::parseHead($g2moddata['headHtml']);
$data['headHtml'] = $g2moddata['headHtml'];
}

/* Add G2 javascript */
if (!empty($javascript)) {
foreach ($javascript as $script) {
$data['javascript'] .= "\n".$script;
}
}

/* Add G2 css */
if (!empty($css)) {
foreach ($css as $style) {
$data['css'] .= "\n".$style;
}
}

// sidebar block
if (isset($g2moddata['sidebarBlocksHtml']) && !empty($g2moddata['sidebarBlocksHtml'])) {
$data['sidebarHtml'] = $g2moddata['sidebarBlocksHtml'];
}

return $data;
}

?>

When I run this I get the following error:
Error (ERROR_MISSING_OBJECT) : Missing object for 23

* in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 2121 (gallerystatus::error)
* in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 305 (mysqldatabasestorage::_identifyentities)
* in modules/core/classes/GalleryStorage.class at line 118 (mysqldatabasestorage::loadentities)
* in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 82 (gallerystorage::loadentities)
* in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 141 (galleryentityhelper_simple::loadentitiesbyid)
* in modules/core/classes/GalleryCoreApi.class at line 2225 (galleryentityhelper_simple::loadentitybyexternalid)
* in modules/core/classes/GalleryEmbed.class at line 184 (gallerycoreapi::loadentitybyexternalid)
* in modules/core/classes/GalleryEmbed.class at line 94 (galleryembed::checkactiveuser)
* in main2.php at line 63 (galleryembed::init)
* in main2.php at line 20

I tried to re-upload that whole folder and it didn't solve my problem so I'm looking for you to help.

Thanks.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Wed, 2005-11-23 02:49

When I run just main.php without the wrapped file it works fine but when I try and run the wrapped file to get the sessions to work as logged in I get the error.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-23 04:24

error missing object -> you didn't map user 23.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Wed, 2005-11-23 04:57

Thank you, If a user clicks register and they register from the gallery what tables are affected? Is there a way to print out the queries that run when a user submits their registration. I'm trying to have users register somewhere else and then insert the data into the tables that I need so I would appreciate it if you could help out with that too.

Thank you.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Wed, 2005-11-23 05:22

The reason why I ask that is because for the users that were created in Gallery and then I map them it seems to work fine, when I try the users that I added to the tables gal2_ExternalIdMap, gal2_User, gal2_UserGroupMap. Those are the three that I thought I would have to populate when I created the user somewhere else but I guess I'm missing something. Please let me know what else I need to do so that I don't get that error.

Thank you.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-23 13:48

make sure your users visit the gallery only from your wrapper file and not any more from main.php.
therefore, change mode.embed.only to true in config.php in g2.

then, all users must visit g2 from the wrapper file. deactivate the register module of g2, then, all users must register with your website.
and your website can call GalleryEmbed::createUser(...); when a user registers, thus automatically synchronizing with g2.

do not tinker with the G2 database tables manually, don't! use the GalleryEmbed methods.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Wed, 2005-11-23 15:04

Whta do I need to pass to GalleryEmbed::createUser(...) so that it will work properly, currently I have the user supplying their username, password, email, first and last names?

Can you also provice an example how the GalleryEmbed::createUser(...) works so I can implement it effectively?

Thank you.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Wed, 2005-11-23 16:41

I tried to use the following code:

require_once("/home/website/.panel/web/gallery2/embed.php");

GalleryEmbed::createUser("$uid", array('username'=>$username,
'email'=>$email,
'fullname'=>$name,
'hashedpassword'=>$password,
'hashmethod'=>'md5'));

And I get the following error:
Fatal error: Undefined class name 'gallerystatus' in /home/website/.panel/web/gallery2/modules/core/classes/GalleryEmbed.class on line 290

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Wed, 2005-11-23 16:42

This is the post information that I'm trying to use to fill the createUser array:

$fname = $_POST['FName'];
$lname = $_POST['LName'];
$email = $_POST['Email'];
$username = $_POST['Username'];
//$username = $_POST['username'];
$date_created = date("m/d/Y");
$password = $_POST['Password'];
$password = md5($password);
$ip = $REMOTE_ADDR;
$time=time();
$name = "$fname $lname";

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-23 23:05

before callong GalleryEmbed::createUser, call GalleryEmbed::init

read modules/core/classes/GalleryEmbed.class, the docs at the beginning.

do not forget to call ::init and ::done.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Fri, 2005-11-25 03:53

Does that map the user in ExternalIdMap or do I have to add that seperatly?

Thanks

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Fri, 2005-11-25 03:56

Sorry about the multiple posts. I will update this if I have any questions.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Fri, 2005-11-25 04:19

Ok I got it to create the user fine for me, when I try and access the gallery through main.php I get the following error:

The username is: treeleaf20 Error (ERROR_MISSING_OBJECT) : 1560 GalleryUser

* in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 138 (gallerystatus::error)
* in modules/core/classes/GalleryCoreApi.class at line 2225 (galleryentityhelper_simple::loadentitybyexternalid)
* in modules/core/classes/GalleryEmbed.class at line 184 (gallerycoreapi::loadentitybyexternalid)
* in modules/core/classes/GalleryEmbed.class at line 94 (galleryembed::checkactiveuser)
* in main2.php at line 63 (galleryembed::init)
* in main2.php at line 20

treeleaf20 was the user that I tried to create, and 1560 is the externalid from the ExternalIdMap table.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-11-25 12:00

you have to call GalleryEmbed::init(array('activeUserId' => $userId, ...));

if you manipulated the externalIdMap manually, you have to call:
yourgalleryUrl/lib/support/ -> delete db cache
afterwards.

and double check there's an entry for externalId = 1560 in your externalIdMap

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Fri, 2005-11-25 18:50

I did do that. The code I use to get the person's externalId is in the query. The code is:

$uid = '';
if (isset($_SESSION['username'])) {
$qry = "Select g2_id from gal2_User where g2_userName = '$_SESSION[username]'";
$result = mysql_query($qry);
$resultsetid = mysql_fetch_array($result);
$uid = $resultsetid[0];
}

// initiate G2
$ret = GalleryEmbed::init(array('embedUri' => 'main2.php',
'embedPath' => '../v-web/gallery2/',
'relativeG2Path' => '../gallery2/',
'loginRedirect' => 'index.php',
'activeUserId' => $uid));
if (!$ret->isSuccess()) {
$data['bodyHtml'] = $ret->getAsHtml();
return $data;
}

So I'm not sure what the problem is. I checked and the 1560 is in the externalIdMap table.

The externalId in the table is 19, the entityType is GalleryUser and the entityId is 1560. I'm not sure where the 19 came from.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Fri, 2005-11-25 19:13

I got it to work now. Thank you.

How do I only allow users who are registered users to view the gallery. Now in main.php it sets them as a guest and still allows a user to view it and I want to make it so that they can only view it if they are logged in and registered. I will take care of checking their username and password but I want it to be something like if the session username isn't set redirect them to the login page.

Thank you for your help so far.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-11-25 19:57

go to your g2, click "edit permissions", remove "view all versions" from the êverybody group.
in the GalleryEmbed::init call, add 'loginRedirect' => '/index.php' or something like that

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Fri, 2005-11-25 22:22

For some reason I don't see the Permissions module anywhere in g2?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-11-25 22:34

permissions are a built in function of the core module. there's no need for a permissions module.

browse to your front page, main.php, not site admin. i repeat, not site admin.

on main.php, logged in as admin, click "edit permissions" in the sidebar links.

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Fri, 2005-11-25 23:04

Would I give the [core] View all Versions to Registered Users if they are entered as GalleryUser in my ExternalIdMap table?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-11-25 23:10

yeah, assign core view all to registered users.

do that in
"edit permissions"

 
treeleaf20

Joined: 2005-11-15
Posts: 64
Posted: Sun, 2005-11-27 16:38

In your comment below:

Quote:
make sure your users visit the gallery only from your wrapper file and not any more from main.php.
therefore, change mode.embed.only to true in config.php in g2.

then, all users must visit g2 from the wrapper file. deactivate the register module of g2, then, all users must register with your website.
and your website can call GalleryEmbed::createUser(...); when a user registers, thus automatically synchronizing with g2.

How do I make them visit main2.php? I can change it to true but is there a space in the config file to redirect them to main2.php? How does it determine what is the wrapper file?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2005-11-27 17:47

all your links that point to g2 should point to your wrapper and not to main.php of course.

if a lost soul tries to access main.php anyway, they will see a error / warning page instead, if you have mode.embed.only = true in config.php.

 
joemonster
joemonster's picture

Joined: 2006-04-12
Posts: 236
Posted: Sun, 2006-08-20 00:47

Is this all good with my php 5 installation?