Logged in user redirection

Notice: This thread is very old.
Azathoth
Member | 495
+
-1
-

You should have redirect in action method, not in createComponent method. Is your signInForm on one page? If it is for example in Sign:in page, you should have redirect

public function actionIn()
{
    $this->redirect(‘Homepage:default’);
}

But you do not have to inject User via constructor, because Presenter (abstract class in Nette, which you extend), already has property User.

But rest of code seems ok. What exactly does not work?

Šaman
Member | 2635
+
+1
-

Problem is that redirect always throw exception.
Take redirect out of try-catch block, or dont catch Nette\Application\AbortException (if exception is AbortException, throw it again in catch block).


Azathoth wrote:

You should have redirect in action method, not in createComponent method. Is your signInForm on one page? If it is for example in Sign:in page, you should have redirect

public function actionIn()
{
    $this->redirect(‘Homepage:default’);
}

This is not true, redirect in onSuccess method (in presenter) is OK. In form factory class is problem that redirect can be called only on presenters or attached components.

But you do not have to inject User via constructor, because Presenter (abstract class in Nette, which you extend), already has property User.

True, dont use $user property on presenters or in templates.

Last edited by Šaman (2015-09-17 13:13)