diff --git a/classes/admin.php b/classes/admin.php index 81fca7aa..45d1b543 100644 --- a/classes/admin.php +++ b/classes/admin.php @@ -19,6 +19,8 @@ use RocketTheme\Toolbox\Session\Message; use RocketTheme\Toolbox\Session\Session; use Symfony\Component\Yaml\Yaml; +define('LOGIN_REDIRECT_COOKIE', 'grav-login-redirect'); + class Admin { /** @@ -72,6 +74,7 @@ class Admin protected $gpm; + /** * Constructor. * @@ -149,7 +152,9 @@ class Admin /** @var Grav $grav */ $grav = $this->grav; - $grav->redirect($this->uri->route()); + + $redirect_route =$this->getLoginRedirect() ?: $this->uri->route(); + $grav->redirect($redirect_route); } } } @@ -518,4 +523,24 @@ class Admin return false; } } + + public function setLoginRedirect() + { + $uri = $this->grav['uri']; + setcookie(LOGIN_REDIRECT_COOKIE, $uri->path(), time() + (86400 * 30), $this->grav['base_url_relative']); + } + + public function getLoginRedirect() + { + if (isset($_COOKIE[LOGIN_REDIRECT_COOKIE])) { + $this->removeLoginRedirect(); + return $_COOKIE[LOGIN_REDIRECT_COOKIE]; + } + return false; + } + + public function removeLoginRedirect() + { + return setcookie(LOGIN_REDIRECT_COOKIE, '', time() - 3600); + } } diff --git a/classes/controller.php b/classes/controller.php index 92083e08..eb41dc12 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -1020,7 +1020,6 @@ class AdminController protected function authoriseTask($task = '', $permissions = []) { if (!$this->admin->authorise($permissions)) { - if ($this->grav['uri']->extension() === 'json') $this->admin->json_response = ['status' => 'unauthorized', 'message' => 'You have insufficient permissions for task ' . $task . '.']; else diff --git a/themes/grav/templates/partials/nav.html.twig b/themes/grav/templates/partials/nav.html.twig index 297d4600..629126b8 100644 --- a/themes/grav/templates/partials/nav.html.twig +++ b/themes/grav/templates/partials/nav.html.twig @@ -3,7 +3,7 @@