代码如下:
程式碼:
//ldapauth
$ldap_server="ldap1.swufe.edu.cn";
$ldap_basedn="********";
$ldap_bindcn="*****".$ldap_basedn;
$ldap_passwd="******";
$ds=ldap_connect($ldap_server);
$dn = "ou=teacher,".$ldap_basedn;
$filter="uid=".$this->userName;
if ($ds)
{
$r=ldap_bind($ds);
$sr=ldap_search($ds,$dn,$filter);
$s_n=ldap_count_entries($ds,$sr);
if ($s_n!=1)
{
$this->_view = new SummaryUserCreationView();
//$this->_form->hasRun( true );
$this->_form->setFieldValidationStatus( "userName", false );
$this->setCommonData( true );
ldap_close($ds);
return false;
}
$info = ldap_get_entries($ds, $sr);
$ldn=$info[0]["dn"];
@$lbind=ldap_bind($ds,$ldn,$this->userPassword);
if (!$lbind)
{
$this->_view = new SummaryUserCreationView();
$this->_view->setErrorMessage( $this->_locale->tr("error_invalid_password"));
$this->_form->setFieldValidationStatus( "userPassword", false );
$this->setCommonData( true );
ldap_close($ds);
return false;
}
} else {
$this->_view = new SummaryUserCreationView();
$this->_view->setErrorMessage( $this->_locale->tr("can_not_connect_ldap"));
$this->_form->setFieldValidationStatus( "userPasswordCheck", false );
$this->setCommonData( true );
ldap_close($ds);
return false;
}