Skip to content

Commit

Permalink
Merge branch 'release/3.7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jan 2, 2023
2 parents 4e10a82 + fb8d92a commit 9082500
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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' }

Expand Down
26 changes: 26 additions & 0 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,6 +63,9 @@ class LoginPlugin extends Plugin
/** @var Invitation|null */
protected $invitation;

protected $temp_redirect;
protected $temp_messages;

/**
* @return array
*/
Expand All @@ -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],
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 9082500

Please sign in to comment.