diff --git a/CHANGELOG.md b/CHANGELOG.md index 78e30e1..f61b561 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v3.7.2 +## 01/02/2023 + +1. [](#new) + * Added new `onBeforeSessionStart()` event to store redirect + messages when session is regenerated during login + * Requires Grav `1.7.38` for new event availability + # v3.7.1 ## 06/14/2022 diff --git a/blueprints.yaml b/blueprints.yaml index a904380..ab7cc36 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Login slug: login type: plugin -version: 3.7.1 +version: 3.7.2 testing: false description: Enables user authentication and login screen. icon: sign-in @@ -15,7 +15,7 @@ bugs: https://github.com/getgrav/grav-plugin-login/issues license: MIT dependencies: - - { name: grav, version: '>=1.7.32' } + - { name: grav, version: '>=1.7.38' } - { name: form, version: '>=6.0.0' } - { name: email, version: '>=3.1.6' } diff --git a/login.php b/login.php index 838470c..da908fa 100755 --- a/login.php +++ b/login.php @@ -23,6 +23,7 @@ use Grav\Common\User\Interfaces\UserInterface; use Grav\Common\Utils; use Grav\Common\Uri; +use Grav\Events\BeforeSessionStartEvent; use Grav\Events\PluginsLoadedEvent; use Grav\Events\SessionStartEvent; use Grav\Framework\Flex\Interfaces\FlexCollectionInterface; @@ -62,6 +63,9 @@ class LoginPlugin extends Plugin /** @var Invitation|null */ protected $invitation; + protected $temp_redirect; + protected $temp_messages; + /** * @return array */ @@ -70,6 +74,7 @@ public static function getSubscribedEvents(): array return [ PluginsLoadedEvent::class => [['onPluginsLoaded', 10]], SessionStartEvent::class => ['onSessionStart', 0], + BeforeSessionStartEvent::class => ['onBeforeSessionStart', 0], PageAuthorizeEvent::class => ['onPageAuthorizeEvent', -10000], 'onPluginsInitialized' => [['initializeSession', 10000], ['initializeLogin', 1000]], 'onTask.login.login' => ['loginController', 0], @@ -124,6 +129,18 @@ public function onPluginsLoaded(): void }; } + /** + * @param BeforeSessionStartEvent $event + * @return void + */ + public function onBeforeSessionStart(BeforeSessionStartEvent $event): void + { + $session = $event->session; + $this->temp_redirect = $session->redirect_after_login ?? null; + $this->temp_messages = $session->messages; + } + + /** * @param SessionStartEvent $event * @return void @@ -132,6 +149,15 @@ public function onSessionStart(SessionStartEvent $event): void { $session = $event->session; + if (isset($this->temp_redirect)) { + $session->redirect_after_login = $this->temp_redirect; + unset($this->temp_redirect); + } + if (isset($this->temp_messages)) { + $session->messages = $this->temp_messages; + unset($this->temp_messages); + } + $user = $session->user ?? null; if ($user && $user->exists() && ($this->config()['session_user_sync'] ?? false)) { // User is stored into the filesystem.