XOOPS完全整合LDAP--編輯使用者


,

作者:cosseto

讓XOOPS完全整合LDAP,就是說要可以更改密碼等等資訊到LDAP....。

更改部分如下

edituser.php
最尾端(或適當位置)加入函數宣告
常數部份請參考註冊HACK那篇

function UpdateLDAP($uid,$mail,$pass)
{
    
//die($uid);//
    
$ldap = ldap_connect(LDAP_HOST);
    
ldap_bind($ldap,LDAP_ADMIN_DN,LDAP_ADMIN_PW);
    
//這邊的條件避免誤刪LDAP內容
    
if(!empty($pass)) { $info['userPassword'] = "{md5}".base64_encode(pack("H*",md5($pass))); }
    if(!empty(
$mail)) { $info['mail'] = $mail; }
    
//更新LDAP
    
ldap_modify($ldap,sprintf(LDAP_BASE_DN,$uid),$info) or die(ldap_error($ldap));
    
//關閉連線
    
ldap_unbind($ldap);
    
ldap_close($ldap);
}


然後在

......
$attachsig = !empty($_POST['attachsig']) ? 1 : 0;
        
$edituser->setVar('attachsig', $attachsig);
        
$edituser->setVar('timezone_offset', $_POST['timezone_offset']);
        
$edituser->setVar('uorder', $_POST['uorder']);
        
$edituser->setVar('umode', $_POST['umode']);
        
$edituser->setVar('notify_method', $_POST['notify_method']);
        
$edituser->setVar('notify_mode', $_POST['notify_mode']);
        
$edituser->setVar('bio', xoops_substr($_POST['bio'], 0, 255));
        
$edituser->setVar('user_occ', $_POST['user_occ']);
        
$edituser->setVar('user_intrest', $_POST['user_intrest']);
        
$edituser->setVar('user_mailok', $_POST['user_mailok']);
        if (!empty(
$_POST['usecookie'])) {
            
setcookie($xoopsConfig['usercookie'], $xoopsUser->getVar('uname'), time()+ 31536000);
        } else {
            
setcookie($xoopsConfig['usercookie']);
        }


之後加入下面

//LDAP 更新
    
$uname = $edituser->getvar('uname');
    
UpdateLDAP($uname,$mail,$password);


這樣就完成囉!