I have an app where the user must be able to login with either their
email address or mobile (cell) phone number. I'm using CakePHP 1.3
with Auth component for authentication and all is well. I even have
the desired functionality working with the below code in the
beforeFilter() of my accounts controller (my users table is called
accounts).

app/controllers/accounts_controller.php

function beforeFilter()
{
    parent::beforeFilter();
    $this->Auth->allow('login', 'logout');
    if ($this->action == 'login') {
        if (!empty($this->data)) {
            if (strpos($this->data['Account']['email'], '@') ===
false) {
                $this->data['Account']['mobile'] = preg_replace('/
[^0-9]/', '', $this->data['Account']['email']);
                unset($this->data['Account']['email']);
                $this->Auth->fields = array('username' => 'mobile',
'password' => 'password');
            } else {
                $this->Auth->fields = array('username' => 'email',
'password' => 'password');
            }
            $this->Auth->login($this->data);
        }
    }
}

And here's the form:

app/views/accounts/login.ctp

<?php
echo $form->create('Account', array('action' => 'login'));
echo $form->input('email', array('label' => 'Email Address or Mobile
Phone Number'));
echo $form->input('password');
echo $form->end('Sign In');
?>

As I said, this works fine. I can login with an emaill address or
mobile phone number. However, if I submit the login form with empty
values (enter nothing and hit submit), I get a blank screen (instead
of the login form with an authMessage).

Any ideas?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to