php - Cakephp 2 : Have two different authentication functions -


i using custom authentification object in cake php. have created file in component/auth/ldapauthenticate.php. in file have function made authentification ldap. looks this:

app::uses('baseauthenticate', 'controller/component/auth'); class ldapauthenticate extends baseauthenticate { public function authenticate(cakerequest $request, cakeresponse $response) {     $username=$request->data["users"]["username"];     $pwd=$request->data["users"]["password"];     $ldap = ldap_connect("ldap:........");     ldap_set_option ($ldap, ldap_opt_referrals, 0);     ldap_set_option($ldap, ldap_opt_protocol_version, 3);      $bind = @ldap_bind($ldap, "test\\".$username, $pwd);     if ($bind && $pwd!="") {         //cakelog::write('debug', "loggé");         $ldap_dn ="dc=world,dc=pcm,dc=local";         $filter = "(&(objectclass=user)(samaccountname=".$username.")(cn=*))";         $justthese = array("cn","mail","givenname","distinguishedname","memberof");         $sr=ldap_search($ldap, $ldap_dn, $filter,$justthese);         $info = ldap_get_entries($ldap, $sr);         ldap_close($ldap);         return $info;     } else {         ldap_close($ldap);         return false;     } } 

}

and log me in user controller :

function login(){         if ($this->request->is('post')) {             if ($this->auth->login()) {                return $this->redirect($this->auth->redirecturl());              }else{                  $this->session->setflash(__('username ou password incorrect'), 'default', array('class'=>'error-message'), 'auth');              } 

i want create second login controller log user database. question have how can create second custom authentication object , call @ right place? want use in function logindist(). there 2 pages authentication, 1 ldap connection , other database connection.

i didn't understand question . give blind shot anyway. think you want support multiply cakephp auth. auth objects purpose. can attach many objects , cakephp check them sequentially , if can identify request, access allowed.

$this->auth->authenticate = array(     'databaseauth',      'ldap' ); 

if auth objects identification in authenticate() method i.e not stataless, don't need setup more include auth objects in correct order , cakephp take on there. conversely if need authenticate yor users first against database above set fine.

but remember though if need parallel auth in app said above need call identify() method manually or implement getuser() method in auth objects cakephp auth function properly

public function logindist(){        $user = $this->auth->identify();       if($user){         $this->auth->allow();        }      // throw 403 exception    } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -