1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-13 01:23:01 +00:00

Redirect to the last page viewed. Fixes #38.

This commit is contained in:
Starbeamrainbowlabs 2015-11-14 15:41:28 +00:00
parent 3711f10e5c
commit 1cca9a9f73
4 changed files with 16 additions and 10 deletions

View file

@ -1158,7 +1158,7 @@ if(!isset($pageindex->{$env->page}) and isset($_GET["search-redirect"]))
// Note we use $_GET here because $env->action isn't populated at this point // Note we use $_GET here because $env->action isn't populated at this point
if($settings->require_login_view === true && // If this site requires a login in order to view pages if($settings->require_login_view === true && // If this site requires a login in order to view pages
!$env->is_logged_in && // And the user isn't logged in !$env->is_logged_in && // And the user isn't logged in
$_GET["action"] !== "login") // And the user isn't requesting the login page !in_array($_GET["action"], [ "login", "checklogin" ])) // And the user isn't trying to login
{ {
// Redirect the user to the login page // Redirect the user to the login page
http_response_code(307); http_response_code(307);
@ -2854,13 +2854,19 @@ register_module([
*/ */
add_action("login", function() { add_action("login", function() {
global $settings; global $settings;
// Build the action url that will actually perform the login
$login_form_action_url = "index.php?action=checklogin";
if(isset($_GET["returnto"]))
$login_form_action_url .= "&returnto=" . rawurlencode($_GET["returnto"]);
$title = "Login to $settings->sitename"; $title = "Login to $settings->sitename";
$content = "<h1>Login to $settings->sitename</h1>\n"; $content = "<h1>Login to $settings->sitename</h1>\n";
if(isset($_GET["failed"])) if(isset($_GET["failed"]))
$content .= "\t\t<p><em>Login failed.</em></p>\n"; $content .= "\t\t<p><em>Login failed.</em></p>\n";
if(isset($_GET["required"])) if(isset($_GET["required"]))
$content .= "\t\t<p><em>$settings->sitename requires that you login before continuing.</em></p>\n"; $content .= "\t\t<p><em>$settings->sitename requires that you login before continuing.</em></p>\n";
$content .= "\t\t<form method='post' action='index.php?action=checklogin&returnto=" . rawurlencode($_SERVER['REQUEST_URI']) . "'> $content .= "\t\t<form method='post' action='$login_form_action_url'>
<label for='user'>Username:</label> <label for='user'>Username:</label>
<input type='text' name='user' id='user' /> <input type='text' name='user' id='user' />
<br /> <br />
@ -2898,8 +2904,8 @@ register_module([
$_SESSION["$settings->sessionprefix-expiretime"] = $expiretime; $_SESSION["$settings->sessionprefix-expiretime"] = $expiretime;
//redirect to wherever the user was going //redirect to wherever the user was going
http_response_code(302); http_response_code(302);
if(isset($_POST["goto"])) if(isset($_GET["returnto"]))
header("location: " . $_POST["returnto"]); header("location: " . $_GET["returnto"]);
else else
header("location: index.php"); header("location: index.php");
exit(); exit();

View file

@ -818,7 +818,7 @@ if(!isset($pageindex->{$env->page}) and isset($_GET["search-redirect"]))
// Note we use $_GET here because $env->action isn't populated at this point // Note we use $_GET here because $env->action isn't populated at this point
if($settings->require_login_view === true && // If this site requires a login in order to view pages if($settings->require_login_view === true && // If this site requires a login in order to view pages
!$env->is_logged_in && // And the user isn't logged in !$env->is_logged_in && // And the user isn't logged in
$_GET["action"] !== "login") // And the user isn't requesting the login page !in_array($_GET["action"], [ "login", "checklogin" ])) // And the user isn't trying to login
{ {
// Redirect the user to the login page // Redirect the user to the login page
http_response_code(307); http_response_code(307);

View file

@ -122,7 +122,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds a pair of actions (login and checklogin) that allow users to login. You need this one if you want your users to be able to login.", "description": "Adds a pair of actions (login and checklogin) that allow users to login. You need this one if you want your users to be able to login.",
"id": "page-login", "id": "page-login",
"lastupdate": 1447514093, "lastupdate": 1447515644,
"optional": false "optional": false
}, },
{ {

View file

@ -18,9 +18,9 @@ register_module([
global $settings; global $settings;
// Build the action url that will actually perform the login // Build the action url that will actually perform the login
$login_form_action_url = "index.php?action=checklogin" $login_form_action_url = "index.php?action=checklogin";
if(isset($_GET["returnto"])) if(isset($_GET["returnto"]))
$login_form_action_url .= "&returnto=" . rawurlencode($_SERVER['REQUEST_URI']); $login_form_action_url .= "&returnto=" . rawurlencode($_GET["returnto"]);
$title = "Login to $settings->sitename"; $title = "Login to $settings->sitename";
$content = "<h1>Login to $settings->sitename</h1>\n"; $content = "<h1>Login to $settings->sitename</h1>\n";
@ -66,8 +66,8 @@ register_module([
$_SESSION["$settings->sessionprefix-expiretime"] = $expiretime; $_SESSION["$settings->sessionprefix-expiretime"] = $expiretime;
//redirect to wherever the user was going //redirect to wherever the user was going
http_response_code(302); http_response_code(302);
if(isset($_POST["returnto"])) if(isset($_GET["returnto"]))
header("location: " . $_POST["returnto"]); header("location: " . $_GET["returnto"]);
else else
header("location: index.php"); header("location: index.php");
exit(); exit();