I am facing an issue with Auth.redirect functionality in Cakephp 2.5.3. Following is the Scenario:
Scenario
There is an action (controller=>TalkComments, action=>add) which is login protected. The data is submitted to this action using POST HTML Method. Now, if the user is not logged in, it takes the user to login view. Once the user logs in, it successfully redirects the user to the required controller and action. The problem is, it does not send the POST data as well, because of which the add() function is not executed.
How can I make the Auth.redirect to also store my post data and send it once the redirectUrl is called.
Following is my code:
UsersController.php
class UsersController extends AppController {
//put your code here
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add', 'login');
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
}
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
public function logout() {
return $this->redirect($this->Auth->logout());
}
public function isAuthorized() {
return true;
}
}
TalkCommentsController.php
class TalkCommentsController extends AppController {
//put your code here
public function add() {
if ($this->request->is('post')) {
$this->TalkComment->create();
if ($this->TalkComment->save($this->request->data)) {
$this->Session->setFlash(__('Comment Saved'));
return $this->redirect($this->referer());
}
$this->Session->setFlash(__('Could not post comment'));
}
}
public function isAuthorized() {
return true;
}
}
Please do let me know if anything else is also required from my end.
Thanks in advance :)