Skip to content

Commit

Permalink
feat: Store request to backlink parameter and resotre it upon next login
Browse files Browse the repository at this point in the history
  • Loading branch information
KminekMatej committed Sep 15, 2024
1 parent 45c563d commit 7c9fa99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/module/core/presenter/front/SecuredPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function startup(): void
if ($this->getUser()->getLogoutReason() === NetteUser::LogoutInactivity) {
$this->flashMessage($this->translator->translate("common.alerts.inactivityLogout"));
}
$this->redirect(':Sign:In:');
$this->redirect(':Sign:In:', ['backlink' => $this->storeRequest()]);
}
}

Expand Down
14 changes: 10 additions & 4 deletions app/module/sign/presenter/front/InPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Tymy\Module\Sign\Presenter\Front;

use Nette;
use Nette\Application\Attributes\Persistent;
use Nette\Application\UI\Form;
use Nette\NotImplementedException;
use Nette\DI\Attributes\Inject;
use Nette\Security\AuthenticationException;
use Tracy\Debugger;
use Tymy\Module\Authentication\Manager\AuthenticationManager;
use Tymy\Module\Core\Manager\BaseManager;
Expand All @@ -13,10 +15,13 @@

class InPresenter extends BasePresenter
{
#[\Nette\DI\Attributes\Inject]
#[Persistent]
public string $backlink = '';

#[Inject]
public SignInFormFactory $signInFactory;

#[\Nette\DI\Attributes\Inject]
#[Inject]
public AuthenticationManager $authenticationManager;

/**
Expand All @@ -29,7 +34,7 @@ protected function createComponentSignInForm(): \Nette\Application\UI\Form
$this->user->setExpiration('20 minutes');
$this->user->login($values->name, $values->password);
BaseManager::logg($this->team, "{$values->name} application login");
} catch (Nette\Security\AuthenticationException $exc) {
} catch (AuthenticationException $exc) {
match ($exc->getMessage()) {
"Login not approved" => $this->flashMessage($this->translator->translate("common.alerts.loginNotApproved"), "danger"),
default => $this->flashMessage($this->translator->translate("common.alerts.loginNotSuccesfull") . ' (' . $exc->getMessage() . ")", "danger"),
Expand All @@ -39,6 +44,7 @@ protected function createComponentSignInForm(): \Nette\Application\UI\Form
$this->initUser();
Debugger::log($this->tymyUser->getCallName() . "@" . $this->team->getSysName() . " logged in");
}
$this->restoreRequest($this->backlink);
$this->redirect(':Core:Default:');
});
}
Expand Down

0 comments on commit 7c9fa99

Please sign in to comment.