Login / integration from non-php system (zope) - Seems to work fine - Sanity check please?

Alias_Knagg

Joined: 2008-04-04
Posts: 2
Posted: Sun, 2008-04-06 13:57

Hi.
Just did this small integration from Zope to G2. Mostly cut and pasted from various examples :)
I would be grateful if somebody more knowledgeable about G2 could have a look and see if it is a total hack or not.
Perhaps some might find it useful as well :)

Basically we have used G1 for our CMS's image handling for several years, and now we want to try G2.

I expect our setup will be either multisite, with one site per customer, or mulitisite + multiroot for the smaller sites.
As the number of editors per customer is small we could probably have done nicely without any user syncing if it was possible to edit the external id of a user in the account view.
As it is I made a small script assertG2User.php that will only accept requests from localhost, and that will verify and/or create the user specified.
When a user in our wysiwyg editor clicks "insert image" this is what happens:

a new window pops open with the url to a python script that
Checks credentials,
calls assertG2User.php
redirects to my embedded gallery with customer id and user id as parameters.

Here's where the hackish part happens :)
This page decides on which multisite to access, then does a G2 login, and then redirects to itself without the parameters.
This is mostly to hide the parameters, and keep the customers from guessing at each others access, but also for for neatness :-/
It took me a long time, and I had to call my script main.php among other things to make it work.
I realize I should probably have synchronized the users password md5 or something instead, but that turned out to be very hard to get hold off from Zope. Or perhaps I should have just generated my own pwd and saved that on the user...

I guess what I really want to ask about is what the "correct" way of logging in to an embedded G2 via http redirect would be.
Does the following code just work by coincidence, or can I reasonably rely on it not being broken by the first upgrade of G2?

function runGallery() {
  $cid = $_REQUEST['cid'];
  if (!$cid) { die('An error occurred'); }

  require_once ("../mx3g/$cid/embed.php");

  $data = array();

  $uid = $_REQUEST['uid'];
  if ($uid) {
    $ret = GalleryEmbed::logout();

    $ret = GalleryEmbed::init(array('fullInit' => true,'embedUri' => '/mx3/main.php'));
    if ($ret) { die('An error occurred'); }
    $ret = GalleryEmbed::login($uid);
    if ($ret) { die('An error occurred'); }
    $ret = GalleryEmbed::done();
    if ($ret) { die('An error occurred'); }
    GalleryUtilities::setResponseHeader("Location: /mx3/main.php");
    GalleryEmbed::handleRequest();
    exit;

  }
  else {
    $ret = GalleryEmbed::init(array('fullInit' => true,'embedUri' => '/mx3/main.php'));
    if ($ret) {
      $data['bodyHtml'] = $ret->getAsHtml();
      return $data;
    }
  }

  $g2moddata = GalleryEmbed::handleRequest();

...