Skip to content

Instantly share code, notes, and snippets.

@fitorec
Created June 28, 2012 03:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fitorec/3008900 to your computer and use it in GitHub Desktop.
Save fitorec/3008900 to your computer and use it in GitHub Desktop.
Cakephp email/username login
<?php
/* Cakephp 2
* Login with email or 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());
}
}
}
@nguyentuandat
Copy link

Many thanks :)

@gerasimua
Copy link

Thank you!

@mandeepkhaleriya
Copy link

can you send me code in cakephp 3.2 for user login form......please help me.......please send me code on my gmail mandeepkhaleriya.08@gmail.com...
please help me..i am new in cake php ......i hope you will reply me.....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment