tags:

views:

153

answers:

1

Hello,

I am developing a website in cakephp. I want to give facility to login either using username or emailid.

I am using. $this->Auth->fields['email'] ='username';

when the login failed and try to relogin again. But till now i haven't got success.

Can anybody suggest me any other idea to that or what i m missing. I have desabled the autorediret also.

+2  A: 

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();
    }
}
deizel