2
  1. When I login from one user account session is set.Then opening the next tab on same browser and enter login url it takes me to the login page.But actually it should redirect to the "dashboard" page(in my case). It can't redirect to loginRedirect(dashboard) page as mentioned in my Auth.
  2. When i logout, as per my code session,cookie and cache are deleted. but it's not redirect to logoutRedirect page.

My code :

App controller

public $components = array(
  'Session', 'RequestHandler', 'Email', 'Cookie',
  'Auth' => array(
    'authenticate' => array(
      'Form' => array(
        'fields' => array(
          'username' => 'email',
          'password' => 'password')
        )
      ),
      'loginRedirect' => array(
         'controller' => 'users',
         'action' => 'login'
       ),
       'logoutRedirect' => array(
         'controller' => 'users',
         'action' => 'login'
       )
     )
   );

User controller

login action :

public function login() {
  $this->layout = 'admin';    
    if ($this->Session->check('Auth.User')) {
      $this->redirect(array('controller' => 'users', 'action' => 'dashboard'));      
    }
    if (isset($this->data['User'])) {
      if (!empty($this->data['User']['email']) && !empty($this->data['User']['password'])) {
        if ($this->Auth->login()) {   
          $this->redirect(array('controller' => 'users', 'action' => 'dashboard'));
        } else {
          $this->set('error', "Email or Password mismatch.");
        }
      }
    } else {
      if ($this->Auth->loggedIn()) {                
        $this->redirect(array('controller' => 'users', 'action' => 'dashboard'));
      }
    }
  } 

logout action :

public function logout() {      
  header('pragma: no-cache'); 
  header('Cache-Control: no-cache, must-revalidate'); 
  $this->response->disableCache();        
  $this->Session->delete('Auth.User');
  $this->Session->delete('User');
  $this->Session->destroy();
  $this->Cookie->destroy();
  return $this->redirect($this->Auth->logout());
}

This code is working fine in "local server" but not working in production server.

Ananthaselvam P
  • 362
  • 2
  • 4
  • 14

1 Answers1

1

Your redirect statements should have return in front of them so that code execution will stop there. For example:

return $this->redirect(array('controller' => 'users', 'action' => 'dashboard'));
user221931
  • 1,852
  • 1
  • 13
  • 16