Backlink storedRequest after user change

4 years ago

ivopisarovic
Member | 5
+
0
-

Hi,
is this normal behaviour?

BasePresenter

	/** @persistent */
	public $backlink = '';

UserPresenter : BasePresenter
Not working:

$this->getUser()->login($values->email, $values->password); // change user from the current logged-in to a new logged-in one.
$this->restoreRequest($this->backlink); // not redirecting, storedRequest not loaded
$this->redirectUrl('/aaa/'); // default redirect

Working:

	private function loadStoredRequest(){
		$key = $this->backlink;
		$session = $this->getSession('Nette.Application/requests');
		if (!isset($session[$key]) || ($session[$key][0] !== NULL && $session[$key][0] !== $this->getUser()->getId())) {
			return ;
		}
		$request = clone $session[$key][1];
		unset($session[$key]);
		$request->setFlag(\Nette\Application\Request::RESTORED, TRUE);
		$params = $request->getParameters();
		$params[self::FLASH_KEY] = $this->getParameter(self::FLASH_KEY);
		$request->setParameters($params);
		$this->request = $request;
		//dump("request Name:", $request->getName());
	}

	private function performStoredRequest(){
		if(isset($this->request)){
			$this->sendResponse(new Nette\Application\Responses\ForwardResponse($this->request));
		}
	}

...

	$this->loadStoredRequest(); // load stored request before new user login
	$this->getUser()->login($values->email, $values->password); // change user
	$this->performStoredRequest(); // redirect ok, forwarded to loaded request
	$this->redirectUrl('/aaa/'); // default redirect

Thanks, Ivo