Auto Login to Gallery2 after user clicks on link from another web site

elzorro

Joined: 2006-06-28
Posts: 14
Posted: Tue, 2007-05-15 16:08

Hello
I hope someone can help me out with this.

Currently I have a site at "http://www.somedomain.com/" at that domain I have virtual directory that points to an instance of G2, which is located at "http://www.somedomain.com/imagegallery/"
I want to just create link from some other domain "http://www.somedomain2.com/" where they login using their credentials and click on a link on that site that will take the to the Gallery2 on the other site and automatically log them in using a generic G2 user.

I know there is a link URL you can use for this but it displays the username and password in the URL which we cant have.

Right now all of the albums are viewable to registered users only. I want visitors coming to the gallery to be able to view the albums without "having to login" if and only if they came in through the link from the other site. If they are not coming from the other site then they would just get the login form as normal.

========================================================
Gallery version = 2.1.1 core 1.1.0.1
PHP version = 5.0.5 isapi
Webserver = Microsoft-IIS/6.0
Database = mysql 5.0.15-nt, lock.system=database
Toolkits = Exif, Thumbnail, Gd
Acceleration = none/86400, none/86400
Operating system = Windows NT 5.2 build 3790
Default theme = emarchive
Locale = en_US
Browser = Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11 =========================================================

Note: continued from http://gallery.menalto.com/node/36918?page=1#comment-234442

Thanks for your help.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2007-05-15 16:50

This has been discussed before.
Please give the forum search function a try, limiting your search to the integration forum.

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

 
shocksll
shocksll's picture

Joined: 2005-06-22
Posts: 352
Posted: Tue, 2007-05-15 17:52

You are going to have to write your own simple integration script.

Modify your em_access.php file and change from

$ret = GalleryEmbed::init(array(
'g2Uri' => $g2_Config['g2Uri'],
'loginRedirect' => $g2_Config['loginRedirect'],
'embedUri' => $g2_Config['embedUri'],
'fullInit' => 'false',
'apiVersion' => array(1,0)
));

to

$UserID = "Anon";
$fullname = "Anonymous";
$ID = 12345;
$Password = "n3v3ergu3$$m3";

$ret = GalleryEmbed::init(array(
'g2Uri' => $g2_Config['g2Uri'],
'loginRedirect' => $g2_Config['loginRedirect'],
'embedUri' => $g2_Config['embedUri'],
'activeUserId' => $ID,
'fullInit' => 'false',
'apiVersion' => array(1,0)
));

if ($ret && !empty($UserID) && !empty($ID))
		{
	    //print_r ($ret);
            // check if there's no G2 user mapped to the activeUserId
            $ret = GalleryEmbed::isExternalIdMapped($ID, 'GalleryUser');
	    //print_r ($ret);
	    //print ($ret->getErrorCode() & ERROR_MISSING_OBJECT);
            if ($ret && ($ret->getErrorCode() & ERROR_MISSING_OBJECT))
            {
                // user not mapped, create G2 user now
				$ret = GalleryEmbed::createUser($ID, array('username' => $UserID, 
                                                'email' => 'none', 'fullname' => $fullname, 
                                                'hashedpassword' => $Password, 'hashmethod' => 'md5'));
                if ($ret)
                {
                    if ($ret->getErrorCode() & ERROR_COLLISION)
                    {
                        list ($ret, $g2user) = GalleryCoreApi::fetchUserByUserName($UserID);
                        if (!$ret)
                        {
                            GalleryEmbed::addExternalIdMapEntry($ID, $g2user->getId(), 'GalleryUser');
                        }
                    }
                }

                GalleryEmbed::checkActiveUser($ID);
            }
		}

If this doesn't work, you might have to play around with it some but it should give you a good start.

Steve Lineberry

 
elzorro

Joined: 2006-06-28
Posts: 14
Posted: Tue, 2007-05-15 18:34

Okay I finally got it to work. I had already looked into integration but was missing one mayor part; Mapping the g2 user to the external app in the [prefix_externalidmap] table.

This is what I ended up with. Thanks for all your help.

Quote:
<?php

//http://codex.gallery2.org/Gallery2:Embedding:Integration
//http://codex.gallery2.org/Gallery2:How_to_visually_embed_G2_in_your_own_website_using_embedded_mode
// 'activeUserId' => '2144
//http://codex.gallery2.org/Gallery2:Embedding:Integration#An_entry_point

$url = $_SERVER['HTTP_REFERER'];

//Parse Refering Page string into its components
$url = parse_url($url);

//make lower case and store in $check
$refurl = strtolower($url["host"]);

if ($refurl == "www.somedomain2.com") {
// If referer is from the authorized site then take them to the gallery
// (not the best solution since its easy to fake but will do.

$g2_Config['path'] = dirname(__FILE__) . '/';

$g2_Config['embedPath'] = '/';
$g2_Config['g2Uri'] = '/imagegallery/';
$g2_Config['loginRedirect'] = '/imagegallery/main.php';
$g2_Config['embedUri'] = '/imagegallery/em_access.php';
$g2_Config['uid'] = '2144';

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'],
'loginRedirect' => $g2_Config['loginRedirect'],
'embedUri' => $g2_Config['embedUri'],
'activeUserId' => $g2_Config['uid'],
'fullInit' => 'false',
'apiVersion' => array(1,0)
));
GalleryCapabilities::set('login',true);

// handle the G2 request
$g2moddata = GalleryEmbed::handleRequest();
// show error message if isDone is not defined
if (!isset($g2moddata['isDone']))
{
print 'isDone is not defined, something very bad must have happened.';
exit;
}
// die if it was a binary data (image) request
if ($g2moddata['isDone'])
{
exit; /* uploads module does this too */
}
if ($ret)
{
print $ret->getAsHtml();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<?php
list($title, $css, $javascript) = GalleryEmbed::parseHead($g2moddata['headHtml']);
echo "<title>" . $title . " -- MySite</title>\n";

foreach ($css as $item) {
echo $item . "\n";
}
foreach ($javascript as $item) {
echo $item . "\n";
}
?>
<style type="text/css"> <!-- /*#gsHeader { display : none; } #gsFooter { display: none; }*/ --> </style>
</head>
<body class="gallery">
<?php
echo $g2moddata['bodyHtml'];
?>
</body>
</html>
<?php
}
else {
// Else if they are not coming for the authorized site send then do nothing
exit;
}
?>

 
fotonut

Joined: 2009-02-21
Posts: 74
Posted: Sat, 2010-02-13 00:01

Can you explain this at a more elementary level for me? I have a Drupal 6.15 configuration with G2.3 imbedded, but off another directory of webroot. I have a simlink from that other directory off webroot that is defined at www.xyz.com/gallery2.

In other words:
(webroot)/mydrupal DNSed as www.xyz.com
(webroot)/mygallery DNSed as gallery.xyz.com

I created /mydrupal/gallery2 simlink that is a mirror image link to actually (webroot)/mygallery

The miracle is, that this all works. What I would like to do now is display some photos from my gallery on my drupal home page that can be seen without someone having to log in. Is this what this script is for? If so, how is it implemented and any suggestions on how to modify for my particular domain + subdomain configuration.

Thank you!

 
fotonut

Joined: 2009-02-21
Posts: 74
Posted: Mon, 2010-09-20 13:49

Well I am starting over on this project. My original failed Gallery 2.3 to Drupal 6(newest) integration has been reconfigured and Gallery2 is no longer in a separate sub-domain where I could never get all the features to work. Gallery2 has been moved a /PhotoGallery sub-directory off my main Drupal site. Good news and minor miracle is that I have the Gallery integrated into my Drupal site with shared passwords and all, plus everything working I can see.

I am looking for code that I can add as a Drupal URL link that will open Gallery2 stand-alone without having to re-enter the password in the stand-alone Gallery2. What do I do? Is the above something I need to experiment with or is this the right track?

THanks!