Since you can set up AuthComponent in the beforeFilter callback, I would assume that you should also be able to do some switching there:
function beforeFilter() {
if (
isset($this->data['User']['login']) && // login form has been posted
Validation::email($this->data['User']['login']) // value looks like an email
) {
$this->Auth->fields = array('username' => 'email'); // change the db field
}
}
If this doesn't work, you may need to try an earlier filter, such as beforeRender, since you need to fire your code before AuthComponent::startup(). As a last resort, you can extend the AuthComponent:
App::import('Component', 'AuthComponent');
class AppAuthComponent extends AuthComponent {
function startup() {
# your code here
parent::startup();
}
}