Integrating Gallery login with my blog

cydewaze
cydewaze's picture

Joined: 2009-08-23
Posts: 33
Posted: Mon, 2010-11-01 22:28

I have a website with a Gallery2 install and a blog. The blog actually pulls content from an IPB blog on another site I host. The problem with this setup is that anyone wanting to comment on my blog would have to find the other site and register there, then find my blog there and comment on it. Obviously not the best setup!

I want to move the blog contents from the IPB forum to my website, and I'd like to use Gallery to handle all the login/authentication stuff, so they don't have to have two accounts. I need advice on how to do the following:

- Make the blog know when someone is logged into the Gallery (probably easy via a cookie or something)
- Make the blog know who is logged into the Gallery

Once I figure out how to do that, I think I can handle the rest.

Thanks for any input!

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Mon, 2010-11-01 22:36
 
cydewaze
cydewaze's picture

Joined: 2009-08-23
Posts: 33
Posted: Mon, 2010-11-01 22:52

By "the other way around" do you mean write my own authentication system and use that for Gallery?

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Mon, 2010-11-01 23:33

gallery has a built-in externalId for identifying users from a blog/cms the way you want would require you to write a way for your blog to identify and check permissions for gallery users.

does your blog not already have some auth system?

http://www.google.com/search?q=gallery2+ipb brings up some helpful stuff.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
cydewaze
cydewaze's picture

Joined: 2009-08-23
Posts: 33
Posted: Tue, 2010-11-02 02:43
Quote:
does your blog not already have some auth system?

Yep, but like I said, that blog is on a totally different site (which happens to be hosted on the same machine) and I don't want users to have to register on that site. Also, I might not host that site forever, so eventually I'll want to move my blog to my own website. Might as well start now rather than do all this twice.

 
cydewaze
cydewaze's picture

Joined: 2009-08-23
Posts: 33
Posted: Fri, 2010-11-05 23:03

Ok, I'm still trying to figure out whether or not a user is logged into my gallery when they're on my sites main index page. I followed a tip in this post, but $userID always seems to equal 5, no matter who is (or isn't) logged in.

I'd ultimately like to somehow capture all the user info (username, Id, etc) on my main index page. Any ideas?

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sat, 2010-11-06 04:02

Ok, so what I'm doing here is first checking for the GALLERYSID cookie:
$currentSession = (isset($_COOKIE['GALLERYSID']) && $_COOKIE['GALLERYSID'] !='TMP_SESSION_ID_DI_NOISSES_PMT')?true : false;
If false, I display my login link which pops a login form.
else if true, I ajax query another script for the user:

    /* Load our GalleryUser */
    var $user, $isAdmin;
    $.ajax({
        type: 'GET',
        dataType: 'json',
        data: {'userInfo':1},
        url: '_assets/userActions.php',
        success: function(data){
            if(data.user){
                $user = data.user;
                $isAdmin = data.isAdmin;
                if($user.userName != 'guest'){
                    //do something
                }
                if($isAdmin){
                    //do something else
                }
            }
        }
    });

userActions.php

snip...

/* Connect to Gallery */
require_once ('/path/to/gallery2/embed.php');
$ret = GalleryEmbed::init(array('fullInit'=>true));
if ($ret) {
    echo 'GalleryEmbed::init failed, here is the error message: '.$ret->getAsHtml();
    exit;
}
GalleryEmbed::done();

...snip...

    $user = $gallery->getActiveUser();
    list ($ret, $isAdmin) = GalleryCoreApi::isUserInSiteAdminGroup();
    if($ret){
        logIt('Error checking is User In Site Admin Group');
    }
    if (is_object($user)) {
        echo json_encode(array('user'=>$user, 'isAdmin'=> $isAdmin));
        exit;
    }
    exit;

...snip

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
cydewaze
cydewaze's picture

Joined: 2009-08-23
Posts: 33
Posted: Sat, 2010-11-06 16:06

I used the info out of your useractions.php, and I get a nice long string with things like the username, full name, hashed password, email, etc. I guess I just need to figure out how to chop it up and pull out the pieces I want. If this was ColdFusion, it would be a piece of cake for me. I'll have to figure out how to do it in PHP, which I'm pretty much a novice in.

The string seems to go "item":"value", so I think I probably need to make an array out of it. Looks like it's time to hit the man pages :p

Thanks for the pointers.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sat, 2010-11-06 16:29

you don't need to json_encode if you're not returning for ajax.

$user = $gallery->getActiveUser(); gets you all you need, the user object and then you can use the built-in getters like: $user->getUserName(); and $user->getFullName() ...
http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryUser.html#sec-method-summary

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
cydewaze
cydewaze's picture

Joined: 2009-08-23
Posts: 33
Posted: Sat, 2010-11-06 18:54

Aha, there we go. I have a nice array-looking thing now, but I can't figure out how to extract the data. I tried $user['userName'] but I get a blank. I think there's some sort of while loop that I'm missing or something. When I do a print_r() on the variable, I can see all the data, but I just can't seem to get to it.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sat, 2010-11-06 19:03
Quote:
$user = $gallery->getActiveUser(); gets you all you need, the user object and then you can use the built-in getters like: $user->getUserName(); and $user->getFullName() ...
http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryUser.html#sec-method-summary

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
cydewaze
cydewaze's picture

Joined: 2009-08-23
Posts: 33
Posted: Sat, 2010-11-06 20:01

lol well yes! That's very useful, if only I knew how to make it work. I think I have a syntax problem or am missing an in-between step. There isn't a sample of how to go from point a to point b.