Hi Everyone,
I am following a recipe from 'Cakephp 1.3 Application Development
Cookbook' By Mariano Iglesias and 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