借助第三方类库adLDAP,将adLDAP.php复制到项目的vendors目录中。修改UserIdentity.php
<?php /** * UserIdentity represents the data needed to identity a user. * It contains the authentication method that checks if the provided * data can identity the user. */ class UserIdentity extends CUserIdentity { public function authenticate() { $ldapConfig = Yii::app()->params['ldap']; Yii::import('application.vendors.*'); require_once('adLDAP.php'); try { $adldap = new adLDAP($ldapConfig); } catch (adLDAPException $e) { echo $e; exit(); } if(!$adldap->authenticate($this->username, $this->password)) $this->errorCode=self::ERROR_PASSWORD_INVALID; else { $adInfo = $adldap->user_info($this->username); $this->setState('ad_info',$adInfo); $this->setState('login_time',time()); $this->errorCode=self::ERROR_NONE; } return !$this->errorCode; } }
Comments