Howto install Gallery in PEAR::Auth?

galleryjed

Joined: 2003-01-09
Posts: 5
Posted: Tue, 2003-01-14 10:05

I have tried to put gallery in a app that uses PEAR::Auth for authentication, and tried using
$gallery->session->username = getUsername();
to pass the username to gallery and avoid a second login, but it doesnt work, then I tried copying and editing the LoggedInUser.php class but that didnt work either.

It just returns to the [login] link...

Does anyone have a document that describes the api on the authentication routines or an example on how to do this I would appreciate it very much :smile:

Setup:
Apache 1.3.26, php 4.2.3 on linux, soon to be replaced by apache 1.3.27, php 4.3.0 on freebsd

Thanks!

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Tue, 2003-01-14 11:22

Hi galleryjed.

The problem is that Gallery has its own user objects with various parameters and flags set for each one. You can see the Abstract_User class file in classes/User.php and the Gallery_User extended class in classes/gallery/User.php. You need to be able to have all of this functionality. (Run <!-- BBCode Start --><A HREF="http://gallery.menalto.com/modules.php?op=modload&amp;name=phpWiki&amp;file=index&amp;pagename=PHP%20Deserializer" TARGET="_blank">php-deserialize.pl</A><!-- BBCode End --> on the userdb.dat or a userfile (located inside albums/.users) to see what parameters are stored).

Duplicating the User databases:
Now, if we assume that you've duplicated your PEAR::Auth userbase into the Gallery user database, then you can just automatically login using the Gallery user database as a shadow, which is much easier than trying to splice the Auth database into Gallery, IMO.

(So you would, in your own login code right below the Auth authentication, pre-load the gallery session with a require("gallery/init.php"), and then set $gallery->session->username = $usernameGrabbedFromPEARAuthentication;) Now when you enter Gallery, your user will already be logged in. Note that this way, the session will be *separate* from your Auth session, so they could potentially expire at different times, leaving you logged in to Gallery but not the rest of the site, or vice-versa. In addition, you have to register/unregister your users into/out of the Gallery database separately. This requires more coding.

Using the Auth database and bypassing a Gallery database:
You could also extend your Auth database to handle all of the functionality of the Gallery user database. (though it would almost be easier to reverse the roles!) Anyhow, if you want to do it this way, you need to replace classes/User.php and classes/gallery/User.php (not LoggedInUser or EverybodyUser or NobodyUser, which just extend the User.php "Abstract_User" class) with your own functions. You'll also need to rework the classes/UserDB.php and classes/gallery/UserDB.php classes with your own functions (which interact with your own Auth database) as well, but preserve the API and prototyping. If you also choose to rewrite session.php, you could avoid having two separate sessions: you just need to be able to replicate the $gallery->session object. I think this is worthwhile myself.

I'm not sure if I just confused you more, but I'll be glad to help you work through either of these options (especially if you're doing the latter and cutting out Gallery's database entirely). I'm interested, because I think having a more seamless way to integrate userbases between Gallery and the website on a whole would be very sensible for a lot of users.

-Beckett (

)

 
galleryjed

Joined: 2003-01-09
Posts: 5
Posted: Tue, 2003-01-14 12:26

Thanks for your reply, I'll try the first option first (seems to be the quickest way, and I need a quick fix).

But I will look into the second option as well, and see if I can get it to work without chaning to much code and mayby post a patch.

But is there any idea to put a lot of effort into this with G2 not to far away (I hope : )?
I will still get this one up and running, the effort part is to post a clean patch to anyone else who might be interested in doing the same thing...

I'll let you know what happens.

//Jed

 
galleryjed

Joined: 2003-01-09
Posts: 5
Posted: Tue, 2003-01-14 22:26

Report sofar...

I tried to duplicate the user dbs (again), using $gallery->session->username = $uname;
Where $uname is the user currently logged in.

No luck.

Tried $gallery->session->username = "test";
Where test is a registred user in gallery.

No luck.

Something has to be really screwed up here.... I started with a fresh install of gallery, added the line
$gallery->session->username = "test";
in albums.php and it didnt work...

Guess that I will take a look at how the classes/User.php and classes/gallery/User.php work and see where I will change the code in there...

//Jed

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Wed, 2003-01-15 05:04

Just remember, before you set $gallery->session->anything, you need to initialise the session and the $gallery object. You do this by calling this line:

require("gallery/init.php"); // (or whatever your path to it is)

Then, you should make sure that the username really is in this $uname variable. It's your responsibility to get the username into $uname. It's not magically in there. Then you can go ahead an do:

$gallery->session->username = $uname;

-Beckett (

)

 
galleryjed

Joined: 2003-01-09
Posts: 5
Posted: Wed, 2003-01-15 08:27

Thats exactly what I did...

My code:
require("gallery/init.php");
// $uName = getUsername();
$uName = "jed";
$gallery->session->username = $uName;

And when I insert
echo "Username: " . $gallery->session->username . "<br>";
in albums.php it prints:
Username: jed
at the top of the page

Do I have to call some ReadGallerySessionAndLogin routine or something?

//Jed