You have to create your own Authenticate component
you have to implement a function that checks if your user can log in and return an array of his data if so or false otherwise.
something like
\Controller\Component\Auth\CompanyAuthenticate.php
App::uses('FormAuthenticate', 'Controller/Component/Auth');
class CompanyAuthenticate extends FormAuthenticate
{
public function authenticate(CakeRequest $request, CakeResponse $response)
{
$user = parent::authenticate($request, $response);
if(!$user)
return false;
else
{
//check company
// if company is ok return $user
// else return false
}
}
}
Edit:
Of course you have to tell your application you are using this kind of authentication
So in your AppController you have to do:
public $components = array(
'Auth' => array(
'authenticate' => array('Company'),
// ... other options
),
// ... other components you wish to load
);