Hi all,
Finally, i think this should work. With this, your user should be logged into the gallery.
Modify the plugin (add the lines in bold) to have :
/**
* Gallery Plugin for MODx
* Written by Raymond Irving, Sept 2005
* Modyfied by Hisanori Muramoto, Feb, 2007
* Integrates Gallery2 with MODx
*
* Events:
* OnWebChangePassword,OnWebDeleteUser,OnWebSaveUser,OnWebLogout
*
* Version: 1.1
*
*/
$e = &$modx->event;
# build mod path
$modpath = $modx->config["base_path"].($mpth ? $mpth:"assets/modules/gallery/");
# include main class
include_once $modpath."g2cms.base.class.inc.php";
$g2base = new G2CMS_Base();
// include Gallery API
require_once($g2base->g2Path.'embed.php');
$ret = GalleryEmbed::init(array(
'embedUri' => $g2base->embedUri,
'g2Uri' => $g2base->g2Uri,
'activeUserId' => $modx->getLoginUserName()
));
if ($ret) {
$modx->logEvent(0,2,$ret->getAsHtml(),'Gallery');
exit;
}
// Event switch
switch($e->name) {
case "OnWebLogin":
$ret = GalleryEmbed::login($modx->getLoginUserName());
if ($ret) {
$modx->logEvent(0,2,$ret->getAsHtml(),'Gallery');
exit;
}
break;
case "OnWebLogout":
$ret = GalleryEmbed::logout(array(
'embedUri' => $g2base->embedUri,
'embedPath' => $g2base->embedPath
));
if ($ret) {
$modx->logEvent(0,2,$ret->getAsHtml(),'Gallery');
exit;
}
break;
case "OnWebSaveUser":
$uid = $username;
$args = array(
'username' => $username,
'fullname' => $userfullname,
'email' => $useremail,
'hashmethod' => 'md5',
'hashedpassword' => md5($userpassword)
);
if($mode=="new") {
$ret = GalleryEmbed::createUser($uid,$args);
if (!$ret->isSuccess()) {
$modx->logEvent(0,2,"Unable to create Gallery user account ($username)<br /><br />".$ret->getAsHtml(),"Gallery");
}
}
else if($mode=="upd"){
$uid=($oldusername ? $oldusername:$username);
if(GalleryEmbed::isExternalIdMapped($uid,'GalleryUser')==null) {
$ret = GalleryEmbed::updateUser($uid,$args);
if (!$ret->isSuccess()) {
$modx->logEvent(0,2,"Unable to update Gallery user account ($username)<br /><br />".$ret->getAsHtml(),"Gallery");
}
}
}
break;
case "OnWebChangePassword":
if(GalleryEmbed::isExternalIdMapped($username,'GalleryUser')==null) {
$ret = GalleryEmbed::updateUser($username,array(
'username'=>$username,
'password'=>$userpassword,
));
if (!$ret->isSuccess()) {
$modx->logEvent(0,2,"Unable to update Gallery user ($username) password<br /><br />".$ret->getAsHtml(),"Gallery");
}
}
break;
case "OnWebDeleteUser":
if(strpos(strtolower($ondel),'delete')!==false) {;
if(GalleryEmbed::isExternalIdMapped($username,'GalleryUser')==null) {
$ret = GalleryEmbed::deleteUser($username);
if (!$ret->isSuccess()) {
$modx->logEvent(0,2,"Unable to update Gallery user ($username) password<br /><br />".$ret->getAsHtml(),"Gallery");
}
}
}
break;
default:
return;
break;
}
i’ve add ’activeUserId’ => $modx->getLoginUserName() to the gallery init, and the onweblogin event.
Finally tick "OnWebLogin" system event. I have to do more tests, be i think it’s close to what i was looking for
If anyone can tell me if this is working on his website...
thanks
nicpan