LdapAuthComponent.php 1008 Bytes
<?php
namespace App\Controller\Component;

use Cake\Controller\Component\AuthComponent;
use Cake\Core\Exception\Exception;
use Cake\ORM\TableRegistry;

class LdapAuthComponent extends AuthComponent
{

    // return FALSE if bad authentication, OR user if ok
    public function connection()
    {
        try {
            // Get login and password entered by the current user (who is trying to connect)
            $login = $this->request->getData('ldap');
            $password = $this->request->getData('password');
            // return user or FALSE
            // calls /Model/Table/LdapConnectionsTable.php/ldapAuthentication()
            return TableRegistry::getTableLocator()->get('LdapConnections')->ldapAuthentication($login, $password);
            //return TableRegistry::get('LdapConnections')->ldapAuthentication($login, $password);
        } catch (Exception $e) {
            var_dump($e->getMessage());
            //return $e->getMessage();
            return FALSE;
        }
    }
}
?>