Skip to content

Instantly share code, notes, and snippets.

@ashutoshdev-zz
Forked from fitorec/UserController.login.php
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save ashutoshdev-zz/61ac71ae635a40f09c4c to your computer and use it in GitHub Desktop.

Select an option

Save ashutoshdev-zz/61ac71ae635a40f09c4c to your computer and use it in GitHub Desktop.
<?php
/* Cakephp 2
* Login with email/username
* Link: http://www.netboy.pl/2011/08/cakephp-auth-component-login-with-username-or-e-mail/#comment-9560
*/
public function login()
{
if( $this->request->is('post') )
{
App::Import('Utility', 'Validation');
if( isset($this->data['User']['username']) && Validation::email($this->data['User']['username']) )
{
$this->request->data['User']['email'] = $this->data['User']['username'];
$this->Auth->authenticate['Form'] = array('fields' => array('username' => 'email'));
}
if( ! $this->Auth->login() )
{
$this->Session->setFlash(__('Invalid username or password, try again'));
}
else
{
$this->redirect($this->Auth->redirect());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment