Embedded G2 getting wrong user account

jonhunt

Joined: 2005-04-24
Posts: 3
Posted: Fri, 2005-06-17 02:39

Hi

I hope someone can help me figure out what's happening here. We have G2 working fine embedded in our CMS in 'guest' mode, but when I try to trigger embedding with a specific G2 User account, it's picking up the wrong account.

eg. two users in g2_Users table
g_id g_userName g_fullName
132 fabien Fabien
140 jonathan Jonathan via Gallery module

Currently the CMS embed code is hardcoded to use 132.

if ($g2session = $ses->get('G2SessionId')) {
          $ret = GalleryEmbed::init(array('embedUri' => '', 'embedPath' => 'Gallery', 'relativeG2Path' => '../../g2', 'loginRedirect' => '/HurlDinger/User/login'.$_SERVER["REQUEST_URI"], 'activeUserId' => '', 'embedSessionString' => $embedSS, 'gallerySessionId' => $g2session));
        } else {
            $ret = GalleryEmbed::init(array('embedUri' => '', 'embedPath' => 'Gallery', 'relativeG2Path' => '../../g2', 'loginRedirect' => '/HurlDinger/User/login'.$_SERVER["REQUEST_URI"], 'activeUserId' => '', 'embedSessionString' => 'G2SID='.$g2session));
            $ses->set('G2SessionId', GalleryEmbed::getSessionId());
        }

        // trying http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=30151&sid=919b7dcc2655edad12341c91a162b78e
        if ($auth = $reg->get('Auth')) {
          if('fabien' == $auth->getUsername()) {
            $ret = GalleryEmbed::isExternalIdMapped('132', 'GalleryUser');
            
            if (!$ret->isError()) {
              // Make G2 User = Externally Mapped WP User.
              GalleryEmbed::checkActiveUser('132');
            }
          }
        } 
        
        if ($ret->isError()) {
            echo $ret->getAsHtml();
            exit;
        }
        GalleryCapabilities::set('showSidebar', false);
        $g2data = GalleryEmbed::handleRequest();

This code works, to the extent that a non-authenticated CMS user gets a guest view of the Gallery, but an authenticated CMS user (fabien, g_id=132) get's to see the Gallery view for jonathan (g_id=40).

Thanks in advance for any assistance...

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-06-17 11:48

the activeUserId parameter in the GalleryEmbed::init() call is not the G2 user id.
It's the id of the user in your CMS.

you have to map the $cmsUserId to the $g2User->getId() with GalleryEmbed::addExternalIdMap() for existing users.

For new G2 users, you can create the G2 user and map it to the cms userId in a single step with GalleryEmbed::createUser();

then you can call GalleryEmbed::init(array(...., 'activeUserId' => $cmsUserId));

your condition to decide whether to login with anonymous user (activeUserId => '') or a real user is a little strange.

In your CMS, you should know if the current cms user is a guest or not, you shouldn't need to check G2SessionId.

you don't have to reinvent the wheel. you could check out how this is done in existing G2 integrations.

 
jonhunt

Joined: 2005-04-24
Posts: 3
Posted: Fri, 2005-06-17 22:48

Thanks for responding.

>the activeUserId parameter in the GalleryEmbed::init() call is not the G2 user id.
>It's the id of the user in your CMS.

Doh, I see I missed that in the 'EMBEDDING' doc.

>you have to map the $cmsUserId to the $g2User->getId() with
> GalleryEmbed::addExternalIdMap() for existing users.

Hmm, I'll need to research that one. I've looked here and on the wiki but is there documentation for the embedding API that I've missed?

In the case that several existing users need to be mapped should I be directly entering data into the mysql table?

>you don't have to reinvent the wheel. you could check out how this is
>done in existing G2 integrations.

Agreed. I've been working of the sample drupal integration code, but it doesn't have much commentary so I've clearly misunderstood some of the method calls...

Cheers
Jonathan