mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-07 22:05:59 +01:00
ability to save and redirect to saved page
This commit is contained in:
@@ -19,6 +19,8 @@ use RocketTheme\Toolbox\Session\Message;
|
|||||||
use RocketTheme\Toolbox\Session\Session;
|
use RocketTheme\Toolbox\Session\Session;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
|
define('LOGIN_REDIRECT_COOKIE', 'grav-login-redirect');
|
||||||
|
|
||||||
class Admin
|
class Admin
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -72,6 +74,7 @@ class Admin
|
|||||||
protected $gpm;
|
protected $gpm;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
@@ -149,7 +152,9 @@ class Admin
|
|||||||
|
|
||||||
/** @var Grav $grav */
|
/** @var Grav $grav */
|
||||||
$grav = $this->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;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1020,7 +1020,6 @@ class AdminController
|
|||||||
protected function authoriseTask($task = '', $permissions = [])
|
protected function authoriseTask($task = '', $permissions = [])
|
||||||
{
|
{
|
||||||
if (!$this->admin->authorise($permissions)) {
|
if (!$this->admin->authorise($permissions)) {
|
||||||
|
|
||||||
if ($this->grav['uri']->extension() === 'json')
|
if ($this->grav['uri']->extension() === 'json')
|
||||||
$this->admin->json_response = ['status' => 'unauthorized', 'message' => 'You have insufficient permissions for task ' . $task . '.'];
|
$this->admin->json_response = ['status' => 'unauthorized', 'message' => 'You have insufficient permissions for task ' . $task . '.'];
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<h3><a href="{{ base_url_relative }}">Grav Admin</a> <a href="{{ base_url_relative_frontend }}"><i class="fa fa-fw fa-angle-double-right"></i></a></h3>
|
<h3><a href="{{ base_url_relative }}">Grav Admin</a> <a href="{{ base_url_relative_frontend }}"><i class="fa fa-fw fa-angle-double-right"></i></a></h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if admin.authorise %}
|
{#{% if admin.authorise %}#}
|
||||||
<div id="admin-user-details">
|
<div id="admin-user-details">
|
||||||
<a href="{{ base_url_relative }}/users/{{ admin.user.username }}">
|
<a href="{{ base_url_relative }}/users/{{ admin.user.username }}">
|
||||||
<img src="http://www.gravatar.com/avatar/{{ admin.user.email|md5 }}?s=32" />
|
<img src="http://www.gravatar.com/avatar/{{ admin.user.email|md5 }}?s=32" />
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{#{% endif %}#}
|
||||||
|
|
||||||
<ul id="admin-menu">
|
<ul id="admin-menu">
|
||||||
<li class="{{ (location == 'dashboard') ? 'selected' : '' }}">
|
<li class="{{ (location == 'dashboard') ? 'selected' : '' }}">
|
||||||
|
|||||||
Reference in New Issue
Block a user