-
-
Save ashutoshdev-zz/61ac71ae635a40f09c4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment