在/module/user/ext/model里新建identify.php,代码如下:

  1. public function identify($account, $password) 
  2.     { 
  3.         if(!$account or !$password) return false; 
  4. /** 
  5. *ldap验证程序块,其中目录树的uid可以取同一个值,只要返回的数组(count>=1)其中有一项密码值通过验证,则表示通过ldap验证;
  6. *系统则不在重复验证密码,但还要验证用户名,因为要检查数据的完整性. 
  7. *----------------------------------------Start---------------------------------------------*/ 
  8. $ldaphost="192.168.0.2"
  9. $ldapport=389
  10. $ldapUid="cn=admin,dc=21com,dc=com"
  11. $ldapPwd="318296"
  12.  
  13. $base_dn="dc=21com,dc=com"
  14. $filter="uid=".$account; 
  15. $attributes=array("userPassword"); 
  16. $ds=ldap_connect($ldaphost,$ldapport) or die(js::error($this->lang->user->loginFailed)); 
  17. if($ds){ 
  18.     ldap_set_option ( $ds, LDAP_OPT_PROTOCOL_VERSION, 3 ); 
  19.     ldap_set_option ( $ds, LDAP_OPT_REFERRALS, 0 ); // Binding to ldap server 
  20.     $bd = ldap_bind($ds, $ldapUid, $ldapPwd)  or die(js::error($this->lang->user->loginFailed)); 
  21.      
  22.     $sr=ldap_search($ds, $base_dn, $filter,$attributes); 
  23.     $count=ldap_count_entries($ds, $sr); 
  24.     if($count>0){ 
  25.         $info=ldap_get_entries($ds, $sr); 
  26.         $ispass=FALSE
  27.         for($i=0;$i<$info['count'];$i++){ 
  28.             $arrpwd=$info[$i]['userpassword']; 
  29.             if(in_array($password, $arrpwd)||in_array(md5($password), $arrpwd)){ 
  30.                 $ispass=TRUE
  31.                 break; 
  32.             } 
  33.         } 
  34.         if($ispass){//通过则进入系统用户名验证 
  35.             $this->dao->update(TABLE_USER)->set('password')->eq(md5($password))->where('account')->eq($account)->exec(); 
  36.         }else{ 
  37.             die(js::error($this->lang->user->loginFailed));die(1); 
  38.         } 
  39.     }else{ 
  40.         die(js::error($this->lang->user->loginFailed));die(2); 
  41.     } 
  42.     ldap_unbind($ds); 
  43. ldap_close($ds); 
  44. /*-------------------------------------End------------------------------------------------*/ 
  45.         /* Get the user first. If $password length is 32, don't add the password condition.  */ 
  46.         $user = $this->dao->select('*')->from(TABLE_USER) 
  47.             ->where('account')->eq($account) 
  48.             //->beginIF(strlen($password) < 32)->andWhere('password')->eq(md5($password))->fi()//不验证密码 
  49.             //->andWhere('deleted')->eq(0)//不验证用户是否禁用 
  50.             ->fetch(); 
  51.  
  52.         /* If the length of $password is 32 or 40, checking by the auth hash. */ 
  53.         if($user and strlen($password) == 32) 
  54.         { 
  55.             $hash = $this->session->rand ? md5($user->password . $this->session->rand) : $user->password; 
  56.             $user = $password == $hash ? $user : ''; 
  57.         } 
  58.         elseif($user and strlen($password) == 40) 
  59.         { 
  60.             $hash = sha1($user->account . $user->password . $user->last); 
  61.             $user = $password == $hash ? $user : ''; 
  62.         } 
  63.  
  64.         if($user) 
  65.         { 
  66.             $ip   = $this->server->remove_addr; 
  67.             $last = $this->server->request_time; 
  68.             $this->dao->update(TABLE_USER)->set('visitsvisits = visits + 1')->set('ip')->eq($ip)->set('last')->eq($last)->where('account')->eq($account)->exec(); 
  69.             $user->last = date(DT_DATETIME1, $user->last); 
  70.         } 
  71.         return $user; 
  72.     } 

有关禅道方法重写的问题请参照禅道插件说明,下面有pdf。