ability to save and redirect to saved page

This commit is contained in:
Andy Miller
2015-07-28 11:11:43 -06:00
parent 80d672a649
commit 7b21fe8a46
3 changed files with 28 additions and 4 deletions

View File

@@ -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);
}
}