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
  • Save ashutoshdev-zz/61ac71ae635a40f09c4c to your computer and use it in GitHub Desktop.
Save ashutoshdev-zz/61ac71ae635a40f09c4c to your computer and use it in GitHub Desktop.

Revisions

  1. @fitorec fitorec revised this gist Jun 28, 2012. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions UserController.login.php
    Original file line number Diff line number Diff line change
    @@ -8,16 +8,15 @@ public function login() {
    if($this->request->is('post')) {
    App::Import('Utility', 'Validation');
    if( isset($this->data['User']['username']) &&
    Validation::email($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')
    );
    $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());
    }
    }
    }
    }
  2. @fitorec fitorec revised this gist Jun 28, 2012. 1 changed file with 11 additions and 14 deletions.
    25 changes: 11 additions & 14 deletions UserController.login.php
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,23 @@
    <?php
    /* Cakephp 2
    * Login with email/username
    * 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') )
    {
    public function login() {
    if($this->request->is('post')) {
    App::Import('Utility', 'Validation');
    if( isset($this->data['User']['username']) && Validation::email($this->data['User']['username']) )
    {
    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'));
    $this->Auth->authenticate['Form'] = array(
    'fields' => array('username' => 'email')
    );
    }
    if( ! $this->Auth->login() )
    {
    if(!$this->Auth->login()) {
    $this->Session->setFlash(__('Invalid username or password, try again'));
    }
    else
    {
    } else {
    $this->redirect($this->Auth->redirect());
    }
    }
    }
    }
  3. @fitorec fitorec created this gist Jun 28, 2012.
    26 changes: 26 additions & 0 deletions UserController.login.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <?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());
    }
    }
    }