External, Background Login

nomorefood

Joined: 2005-08-27
Posts: 6
Posted: Tue, 2005-10-04 05:49

I really wouldn't call what I'm doing 'embedding' so I don't know if I have to use the empedding API or not; I was hoping someone could enlighten me. Here is my situation: Gallery2 has a completely standalone copy with its own users. I have an non-gallery page that I would like to make into a single-signon for all the relevant services (g2 being one of them).

Given I have the user's USERNAME, how can I lookup the Gallery2 account and setup the session so when I navigate to the Gallery2 pages, it's as if they logged in via the gallery page. Below is what I'm using to create a user from my single-register for user registration. I was hoping I could make something similar for single-signon.

// 
// Add User To Gallery
//
$username = $values['username'];
$fullname = $values['firstname'] . " " . $values['lastname'];
$email = $values['email'];
$password = $values['password'];

include('./gallery/bootstrap.inc');
include('./gallery/init.inc');

$ret = GalleryInitFirstPass();
$ret = GalleryInitSecondPass();
GalleryCoreApi::loadPlugin('module', 'core', true);  

$GalleryUser = new GalleryUser();
$GalleryUser->create($username); 
$GalleryUser->setemail($email);
$GalleryUser->setfullName($fullname);
$GalleryUser->changePassword($password); 
$GalleryUser->save();

Any ideas?

Thanks,

- Bryan

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-10-04 08:19

GalleryEmbed is our solution to single-sign on.
please use GalleryEmbed.

see: docs/EMBEDDING, sticky embedding and integration topic, existing integrations (wpg2, mambo, drupal, xaraya, ..) as examples.

 
nomorefood

Joined: 2005-08-27
Posts: 6
Posted: Tue, 2005-10-04 23:59

Yeah, I've been doing that. Anyone have any idea why the following doesn't work? I go straight to the page and see 'Initialization Complete' -- no errors. Then I go to the main gallery page and I'm not logged in.


  $embedPath = 'gallery/embed.php';

  if (!is_readable('gallery/embed.php')) {
     printf("Gallery path not readable");
  }	 
  include_once($embedPath);

  $ret = GalleryInitFirstPass();
  if ($ret->isError()) {
     printf("Problem with initial pass<br>");
  }

  list ($ret, $core) = GalleryCoreApi::loadPlugin('module', 'core', true);  
  if ($ret->isError()) {
     printf("Error Loading API<br>");
  }

  list ($ret, $g2_user) = GalleryCoreApi::fetchUserByUsername('nomorefood');
  if ($ret->isError) {
     printf("Error Locating User<br>");
  }

  if (!isset($g2_user)) {
	 printf("Gallery User Invalid<br>");
  } 

  $params = array('embedPath' => $embedPath,
                  'relativeG2Path' => 'gallery/',
                  'activeUserId' => $g2_user->uid,
                  'activeLanguage' => $g2_user->language,
                  'fullInit' => true);

  $ret = GalleryEmbed::init($params);
  if ($ret->isError) {
     printf("Error Initializing Gallery<br>");
  } 
  
  $ret = GalleryEmbed::handleRequest();
  if ($ret->isError) {
     printf("Error Handling Request<br>");
  } 
  
  printf("Initialization Complete<br>");
  
  exit();

 
nomorefood

Joined: 2005-08-27
Posts: 6
Posted: Wed, 2005-10-05 00:27

Ugh, I must have copied/paste code from too many places. Needed to make g2_User->uid g2_User->getId(); and had to add GalleryEmbed::login();

Working now. Thanks

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-10-05 06:33

nope, still too much unneeded code.

- instead of include_once use require_once, this has built in error handling and will error out if embed.php isn't around.
- GalleryInitFirstPass isn't required, GalleryEmbed::init takes care of that. use fullInit => true in the ::init call.
- GalleryCoreApi::loadPlugin not needed
- 'activeUserId' => $g2_user->uid, isn't the way it's supposed to work

let's get back to your issue, maybe i misunderstood you:

Quote:
Gallery2 has a completely standalone copy with its own users. I have an non-gallery page that I would like to make into a single-signon for all the relevant services (g2 being one of them).

usually, the term single-sign-on is used if you have multiple scripts / applications and you want to use a single login for them. such that when you're logged into application A, you're also logged into the other application(s).

is G2 the only application on your website with user management / login?
do you just want to add a login box on your other page? then you just have to copy the login form html to your other page and set the cookie path in site admin -> general to /