Location: PHPKode > projects > w-agora > w-agora/user/ldap_example.php
<?php

/*
 *	W-AGORA 4.1
 *	-----------
 *	$Id: ldap_example.php,v 1.3 2002/06/10 14:32:53 mdruilhe Exp $
 *	 Usage:		Example user source class for ldap authentication
 *	 Author:	Alastair Foreman <hide@address.com>
 */	

if (!defined('_GLOBALS')) {
	die('Hacking attempt');
}

if (!defined("_AUTH")) {
        include ("$inc_dir/auth.$ext");
}

// NOTE: filename must be "<something>_user.php"
//       class name must be "<filename>_source"
//
class <put filename here>_source extends wa_Auth {

function getRegisterURL() {
    //empty string means disabled
    return "";
}

function getForgotPasswordURL() {
    //empty string means disabled
    return "";
}

function getChangePasswordURL() {
    //empty string means disabled
    return "";
}

function getEditProfileURL() {
    //empty string means disabled
    return "";
}

 function getLoginURL() {
	//return nothing means use w-agora Login FORM
	return;
 }

function encryptPassword($password) {
    //No encryption (?)
    return $password;
}

 function getLoginInfo () {
	 return;
 }

 function authenticateUser($site, $userid, $encryptedpw) {

	global $db;

    $ds=ldap_connect("<server>");
    if (! $ds) {
        //error connecting - return false
        return false;
    }
    
    $r=ldap_bind($ds, "uid=$userid, o=<some base>", $encrptedpw);
    if ($r) {
        $attr_array = array("cn", "gn", "sn" /*and other fields*/);
        $result = ldap_read($ds, "uid=$userid, o=<some base>",
                            "objectclass=<some class>", $attr_array);
    }
    ldap_close($ds);

    if (! $result) {
        //error reading / authenticating  - return false
         return false;
    }
 
    //now create the array to return to w-Agora
    #printf("%s = %s, ", "username",    $result["cn"][0]);
    #printf("%s = %s, ", "name",        $result["sn"][0]);
    #printf("%s = %s, ", "firstname",   $result["gn"][0]);

    $this->user["userid"]      = $userid;
    $this->user["password"]    = $encryptedpw;
    $this->user["username"]    = $result["cn"][0];
    $this->user["name"]        = $result["sn"][0];
    $this->user["firstname"]   = $result["gn"][0];
    #$this->user["useraddress"] =
    #$this->user["homepage"]    =
    #$this->user["details"]     =
    #$this->user["mailok"]      =

	#authenticated -- now merge any remaining fields from db if required
	$agoradb_user = $db->getUser($site, $userid);
	if (is_array($agoradb_user)) {
		$this->user = array_merge($agoradb_user, $this->user);
	}

    return true;
 }

} // end class
?>
Return current item: w-agora