From d7ca7125ce500d220f20b30d8317c54f73dc9c99 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Thu, 27 Dec 2018 00:15:27 -0700 Subject: [PATCH] Nicer access denied message --- index.php | 43 +++++++++++++++++++++++++++---------------- langs/en/core.json | 6 +----- langs/en/index.json | 8 ++++++++ 3 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 langs/en/index.json diff --git a/index.php b/index.php index 5cac7ba..1bdd70d 100644 --- a/index.php +++ b/index.php @@ -13,8 +13,19 @@ if (!empty($_SESSION['loggedin']) && $_SESSION['loggedin'] === true && !isset($_ die(); } -if (!empty($_GET['logout'])) { - // Show a logout message instead of immediately redirecting to login flow +/** + * Show a simple HTML page with a line of text and a button. Matches the UI of + * the AccountHub login flow. + * + * @global type $SETTINGS + * @global type $SECURE_NONCE + * @global type $Strings + * @param string $title Text to show, passed through i18n + * @param string $button Button text, passed through i18n + * @param string $url URL for the button + */ +function showHTML(string $title, string $button, string $url) { + global $SETTINGS, $SECURE_NONCE, $Strings; ?> @@ -26,7 +37,6 @@ if (!empty($_GET['logout'])) { -
@@ -54,24 +59,25 @@ if (!empty($_GET['logout'])) {
-

get("You have been logged out.") ?>

+

get($title); ?>

- - hasPermission($perm)) { - die($Strings->get("no access permission", false)); + showHTML("no access permission", "sign out", "./action.php?action=signout"); + die(); } } Session::start($user); $_SESSION["login_code"] = null; header('Location: app.php'); - die("Logged in, go to app.php"); + showHTML("Logged in", "Continue", "./app.php"); + die(); } else { throw new Exception(); } @@ -113,7 +121,10 @@ if ($redirecttologin) { $_SESSION["login_code"] = $codedata["code"]; - header("Location: " . $codedata["loginurl"] . "?code=" . htmlentities($codedata["code"]) . "&redirect=" . htmlentities($redirecturl)); + $locationurl = $codedata["loginurl"] . "?code=" . htmlentities($codedata["code"]) . "&redirect=" . htmlentities($redirecturl); + header("Location: $locationurl"); + showHTML("Continue", "Continue", $locationurl); + die(); } catch (Exception $ex) { sendError($ex->getMessage()); } diff --git a/langs/en/core.json b/langs/en/core.json index 6121060..f2d85fb 100644 --- a/langs/en/core.json +++ b/langs/en/core.json @@ -1,11 +1,7 @@ { - "You have been logged out.": "You have been logged out.", - "Log in again": "Log in again", - "login server unavailable": "Login server unavailable. Try again later or contact technical support.", "sign out": "Sign out", "404 error": "404 Error", "page not found": "Page not found.", "invalid parameters": "Invalid request parameters.", - "login server error": "The login server returned an error: {arg}", - "no access permission": "You do not have permission to access this system." + "login server error": "The login server returned an error: {arg}" } diff --git a/langs/en/index.json b/langs/en/index.json new file mode 100644 index 0000000..c516bbb --- /dev/null +++ b/langs/en/index.json @@ -0,0 +1,8 @@ +{ + "You have been logged out.": "You have been logged out.", + "Log in again": "Log in again", + "login server unavailable": "Login server unavailable. Try again later or contact technical support.", + "no access permission": "You do not have permission to access this system.", + "Logged in": "Logged in", + "Continue": "Continue" +}