It mainly depend of the Auth setting. By default you would not go
trough the login action before Auth will do, so your code is useless
since Auth will handle the login before your login code (when $this-
>data is not empty).
My best guess is to handle this in beforeFilter of the user
controller, a bit like this:

// switch username to email when @ found in login name

if($this->action == 'login' && strpos($this->data['User']['username'],
'@') !== false))
{
   $this->data['User']['email'] = $this->data['User']p'username'];
   unset($this->data['User']['username']);
    $this->Auth->fields['username']='email';
}


PS: Hi Mariano, so long time !!

On Apr 13, 3:27 am, "mariano.iglesias" <[email protected]>
wrote:
> I just followed the recipe from scratch and found no issues. I am able
> to log in with either a user account, or an email. Can you set DEBUG
> to 2 (in your app/config/core.php file) and paste the queries that are
> shown?
>
> On Apr 11, 5:42 pm, john lyles <[email protected]> wrote:
>
> > Hi Everyone,
> > I am following a recipe from 'Cakephp 1.3 Application Development
> > Cookbook' ByMarianoIglesiasand I am stuck with the recipe 'Allowing
> > logins with username or email' on page 16 of the book.
>
> > The recipe works except one problem which I cannot figure out. If I
> > login with the email instead of the username the loginError message
> > flashes on the screen. This doesn't happen if I login using the
> > username.
>
> > I should note also that you have to do the basic auth setup before you
> > can do this recipe, and the basic setup works with no issues that I
> > have noticed so far.
>
> > This is what the login action of the Users Controller looks like:
>
> > public function login() {
> >   if (
> >     !empty($this->data) &&
> >     !empty($this->Auth->data['User']['username']) &&
> >     !empty($this->Auth->data['User']['password'])
> >   ) {
> >     $user = $this->User->find(
> >       'first', array(
> >         'conditions' => array(
> >         'User.email' => $this->Auth->data['User']['username'],
> >         'User.password' => $this->Auth->data['User']['password']
> >       ),
> >       'recursive' => -1
> >     ));
> >   if (!empty($user) && $this->Auth->login($user)) {
> >     if ($this->Auth->autoRedirect) {
> >       $this->redirect($this->Auth->redirect());
> >     }
> >   } else {
> >       $this->Session->setFlash($this->Auth->loginError, $this->Auth-
>
> > >flashElement, array(), 'auth');
> >   }
> > }
> > }

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to