Login redirection problems after server change

cowmoo

Joined: 2007-07-18
Posts: 20
Posted: Thu, 2007-11-15 01:09

Hey again,
I've been working on my small integration script, and it's been working very well, until now. :(
I've changed to a new server (the environment is exactly the same or very close too) and now my script is redirecting people to what seems like the login page, with a welcome message instead of the user name / pass boxes. From there, if they click the 'Your Album' link (I'm using useralbum mod) it will direct them to their album, but I want this to happen as soon as they log in.
the 'Jump to user album after login' option is selected in useralbum.
This worked fine on my other server, but in that installation there were some extra modules that I no longer use, thus they have been deleted.
I've tried setting loginRedirect in the init call, but that didn't seem to have an effect (the url was changed but thats all).
any help would be appreciated.

The script redirects here after login (split over 3 lines for readability):
http://www.example.com/main.php?g2_view=core.UserAdmin&g2_subView=core.UserLogin&g2_return=
%2Fmain.php%3Fg2_0%3D5f4dcc3b5aa765d61d8327deb882cf99%26g2_GALLERYSID%3D1a8005858ae81c2f22353fa3e4c90859&g2_returnName=
album&g2_GALLERYSID=1a8005858ae81c2f22353fa3e4c90859

I want it to redirect here:
http://www.example.com/main.php?g2_controller=useralbum.UserAlbum&g2_navId=x60c6195d&g2_authToken=707f5c61b8ac

the code for my script (main_wrapper.php):

<?php

$db = mysql_connect("www.example.com:4406","dbuser","dbpass") or die("Unable to connect to Server.");
mysql_select_db("database",$db) or die( "Unable to select database.");

$sql = "SELECT blah FROM blah WHERE blah";

$res = mysql_query($sql, $db) or die(mysql_error);
$row = mysql_fetch_assoc($res);
if($row)
{
	$data = runGallery($row['blah'], $row['blah'], $row['blah']);
	$data['title'] = (isset($data['title']) && !empty($data['title'])) ? $data['title'] : 'Gallery';

	if (isset($data['bodyHtml'])) {
		print "<!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>";
	}
} else {
	print "You must have an account with XXXXX to use this feature";
}


function runGallery($firstName, $lastName, $contactEmail) {

    require_once('./embed.php');
    
	$data = array();
	
    // if anonymous user, set g2 activeUser to ''
    $uid = $_GET['u'];
    $upass = $_GET['p'];
 
    // initiate G2 
    $ret = GalleryEmbed::init(array('g2Uri' => 'www.example.com/', 
				    'embedUri' => '/main.php',
				    'activeUserId' => $uid));

	if ($ret && $ret->getErrorCode() & ERROR_MISSING_OBJECT) {
		/* The user does not exist in G2 yet. Create in now on-the-fly */
		$ret = GalleryEmbed::createUser($uid, array('username' => $uid,
'email' => $contactEmail, 'fullname' => $firstName." ".$lastName,
'hashedpassword' => $upass, 'hashmethod' => 'md5'));

		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>";
			/* add mails in to inform me when errors occour */
			print $ret->getAsHtml();
			exit;
		}
	} elseif ($ret) {
		/* The error we got wasn't due to a missing user, it was a real error */
		if ($ret) {
			print "An error occurred while checking if a user already exists<br>";
			print $ret->getAsHtml();
		}
		print "An error occurred while trying to initialize G2<br>";
		print $ret->getAsHtml();
		exit;
	}

	/* locking the user to disallow changing of details through gallery */
	list ($ret, $user) = GalleryCoreApi::loadEntityByExternalId($uid, 'GalleryUser');
	if($ret)
	{
		print "An error occurred while loading the user object<br>";
		print $ret->getAsHtml();
	} else {
		list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($user->getId());
		if($ret)
		{
			print "An error occurred while loading the user object<br>";
			print $ret->getAsHtml();
		} else {
			$user->setLocked(true);
			$user->save();
		}
	}
	GalleryCoreApi::releaseLocks($lockId);


    if ($ret) {
      $data['bodyHtml'] = $ret->getAsHtml();
      return $data;
    }

	// BEGIN ALBUM REDIRECT STUFF
	// Before initializing the user session, let's get the user's default album:	
	// First return array with all Gallery user data in Guser
	list ($ret, $user) = GalleryCoreApi::fetchUserByUsername('admin');
	if ($ret && !($ret->getErrorCode() & ERROR_MISSING_OBJECT)) {
		$data[error] = "An error occurred <br>";
		$data[error] .= $ret->getAsHtml();
	return $data;
	}
	// Now return the user's default albumID
	list ($ret, $userAlbumID) =
	GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $user->getId());
	if ($ret) {
    	$data[error] = "An error occurred <br>";
    	$data[error] .= $ret->getAsHtml();
    	return $data;
	}
	//Now set the default userAlbumID
	$gallery->setConfig('defaultAlbumId', intval($userAlbumID));
	$gallery->setConfig('breadcrumbRootId', intval($userAlbumID));

	// END ALBUM REDIRECT STUFF

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

	GalleryEmbed::checkActiveUser($uid);
    // 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  */
    $data['javascript'] = '';
    if (!empty($javascript)) {
      foreach ($javascript as $script) {
	     $data['javascript'] .= "\n".$script;
      }
    }

    /* Add G2 css  */
    $data['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;
}


?>

* the URL to your Gallery (seeing the problem is very helpful).
Sorry not accessible to outside world
* the version of Gallery,
2.2.3 core 1.2.0.5
* the version of PHP,
5.2.3-1ubuntu6 apache2handler
* the version of Apache,
Apache/2.2.4 (Ubuntu) PHP/5.2.3-1ubuntu6
* your operating system and hardware,
Linux as-box 2.6.22-14-generic #1 SMP Sun Oct 14 23:05:12 GMT 2007 i686, running on a 2.4G quad-core, on some intel board
* (if applicable) the web browser and version you are using,
dont think it's the problem but, Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8) Gecko/20071022 Ubuntu/7.10 (gutsy) Firefox/2.0.0.8

Anyone know what might be going on here?

Thanks in advance,
cOwMoO

 
cowmoo

Joined: 2007-07-18
Posts: 20
Posted: Mon, 2007-11-19 06:58

Anyone got any ideas? I honestly can't work out why this is happening. I've never seen a redirect to that page before, and can't see where it's happening.

 
cowmoo

Joined: 2007-07-18
Posts: 20
Posted: Tue, 2007-11-20 01:08

Sorry bout the pics everyone, but can't give access to my gallery, it's the best I can do atm, ask if you would like to see any of the source.
I have still got nowhere with this, currently my script logs user in, but redirects to the following page:

[img]http://images.frozenbear.com:9090/i/picfu0/2007/11/19/17/1/5/a/15a3621c4006998ea1443495d33514350_main.jpg[/img]
As you can see, there are a few problems there.

Aswell as the problems shown in the pic, there is also some extra whitespace around the entire site, and the url still points to the wrapper file instead of main.php.
I would like my script to create / login user then pass info to gallery, then load gallery as normal (not embedding etc).

Also with the problems in that pic, gallery seems to think that the users album is the root album for some reason (might be wrong here).

If you click on the 'Your album' link, it will take you to the root album, seen here:

[img]http://images.frozenbear.com:9090/i/picfu0/2007/11/19/17/e/f/e/efe1277b176d89bb037b99a5baf6e6900_main.jpg[/img]
Everything on this page appears properly, however the link should've taken them to their own album, not the root album.

just for reference, here is where I want the user to be taken straight from login:

[img]http://images.frozenbear.com:9090/i/picfu0/2007/11/19/17/0/3/3/033b9f282b061030ba2293e797c4016a0_main.jpg[/img]

Any help would be greatly appreciated, I just need to know where this is happening.
Thanks
cOwMoO