I am having trouble getting the Auth component redirect.
I have a login form and I want to keep the user on the page he logs in on. For example, if he is viewing contact us page, I want to keep him there after logging in.I have made loginaction page as my login page to validation purpose.Otherwise i can’t validate for password blank field. Here is my user’s controller code :
function beforeFilter(){
$this->Auth->allow('register');
$this->Auth->autoRedirect = false;
parent::beforeFilter();
}
function loginaction(){
if($this->data){
if($this->data['User']['email']=='')
$this->Session->setflash('E-Mail cannot be blank');
elseif ($this->data['User']['password']=='')
$this->Session->setflash('Password cannot be blank');
else {
$this->data['User']['password']=$this->Auth->password($this->data['User']['ppassword']);
if($this->User->validateUser($this->data)){
$this->Auth->login($this->data);
$this->redirect($this->Auth->redirect());
}
}
and following is my app_controller code:
function beforeFilter(){
$this->Auth->fields = array(
'username' => 'email',
'password' => 'password'
);
$this->Auth->loginAction=array('controller'=>'users', 'action'=>'loginaction');
}
This will redirecting to the page from where user logged out.But i want redirection should happen to the page from where user clicks the login button. I am not getting where i am wrong.
If you need to redirect to the referer page you can use: