Browse Source

Nicer access denied message

master
Skylar Ittner 6 months ago
parent
commit
d7ca7125ce
3 changed files with 36 additions and 21 deletions
  1. 27
    16
      index.php
  2. 1
    5
      langs/en/core.json
  3. 8
    0
      langs/en/index.json

+ 27
- 16
index.php View File

@@ -13,8 +13,19 @@ if (!empty($_SESSION['loggedin']) && $_SESSION['loggedin'] === true && !isset($_
13 13
     die();
14 14
 }
15 15
 
16
-if (!empty($_GET['logout'])) {
17
-    // Show a logout message instead of immediately redirecting to login flow
16
+/**
17
+ * Show a simple HTML page with a line of text and a button.  Matches the UI of
18
+ * the AccountHub login flow.
19
+ *
20
+ * @global type $SETTINGS
21
+ * @global type $SECURE_NONCE
22
+ * @global type $Strings
23
+ * @param string $title Text to show, passed through i18n
24
+ * @param string $button Button text, passed through i18n
25
+ * @param string $url URL for the button
26
+ */
27
+function showHTML(string $title, string $button, string $url) {
28
+    global $SETTINGS, $SECURE_NONCE, $Strings;
18 29
     ?>
19 30
     <!DOCTYPE html>
20 31
     <meta charset="UTF-8">
@@ -26,7 +37,6 @@ if (!empty($_GET['logout'])) {
26 37
     <link rel="icon" href="static/img/logo.svg">
27 38
 
28 39
     <link href="static/css/bootstrap.min.css" rel="stylesheet">
29
-    <link href="static/css/svg-with-js.min.css" rel="stylesheet">
30 40
     <style nonce="<?php echo $SECURE_NONCE; ?>">
31 41
         .display-5 {
32 42
             font-size: 2.5rem;
@@ -40,11 +50,6 @@ if (!empty($_GET['logout'])) {
40 50
             border: 1px solid grey;
41 51
             border-radius: 15%;
42 52
         }
43
-
44
-        .blank-image {
45
-            height: 100px;
46
-            margin: 2em auto;
47
-        }
48 53
     </style>
49 54
 
50 55
     <div class="container mt-4">
@@ -54,24 +59,25 @@ if (!empty($_GET['logout'])) {
54 59
             </div>
55 60
 
56 61
             <div class="col-12 text-center">
57
-                <h1 class="display-5 mb-4"><?php $Strings->get("You have been logged out.") ?></h1>
62
+                <h1 class="display-5 mb-4"><?php $Strings->get($title); ?></h1>
58 63
             </div>
59 64
 
60 65
             <div class="col-12 col-sm-8 col-lg-6">
61 66
                 <div class="card mt-4">
62 67
                     <div class="card-body">
63
-                        <a href="./index.php" class="btn btn-primary btn-block"><?php $Strings->get("Log in again"); ?></a>
68
+                        <a href="<?php echo $url; ?>" class="btn btn-primary btn-block"><?php $Strings->get($button); ?></a>
64 69
                     </div>
65 70
                 </div>
66 71
             </div>
67 72
         </div>
68 73
     </div>
69
-
70
-    <script src="static/js/fontawesome-all.min.js"></script>
71 74
     <?php
72
-    die();
73 75
 }
74 76
 
77
+if (!empty($_GET['logout'])) {
78
+    showHTML("You have been logged out.", "Log in again", "./index.php");
79
+    die();
80
+}
75 81
 if (empty($_SESSION["login_code"])) {
76 82
     $redirecttologin = true;
77 83
 } else {
@@ -84,13 +90,15 @@ if (empty($_SESSION["login_code"])) {
84 90
             $user = new User($uidinfo['uid'] * 1);
85 91
             foreach ($SETTINGS['permissions'] as $perm) {
86 92
                 if (!$user->hasPermission($perm)) {
87
-                    die($Strings->get("no access permission", false));
93
+                    showHTML("no access permission", "sign out", "./action.php?action=signout");
94
+                    die();
88 95
                 }
89 96
             }
90 97
             Session::start($user);
91 98
             $_SESSION["login_code"] = null;
92 99
             header('Location: app.php');
93
-            die("Logged in, go to app.php");
100
+            showHTML("Logged in", "Continue", "./app.php");
101
+            die();
94 102
         } else {
95 103
             throw new Exception();
96 104
         }
@@ -113,7 +121,10 @@ if ($redirecttologin) {
113 121
 
114 122
         $_SESSION["login_code"] = $codedata["code"];
115 123
 
116
-        header("Location: " . $codedata["loginurl"] . "?code=" . htmlentities($codedata["code"]) . "&redirect=" . htmlentities($redirecturl));
124
+        $locationurl = $codedata["loginurl"] . "?code=" . htmlentities($codedata["code"]) . "&redirect=" . htmlentities($redirecturl);
125
+        header("Location: $locationurl");
126
+        showHTML("Continue", "Continue", $locationurl);
127
+        die();
117 128
     } catch (Exception $ex) {
118 129
         sendError($ex->getMessage());
119 130
     }

+ 1
- 5
langs/en/core.json View File

@@ -1,11 +1,7 @@
1 1
 {
2
-    "You have been logged out.": "You have been logged out.",
3
-    "Log in again": "Log in again",
4
-    "login server unavailable": "Login server unavailable.  Try again later or contact technical support.",
5 2
     "sign out": "Sign out",
6 3
     "404 error": "404 Error",
7 4
     "page not found": "Page not found.",
8 5
     "invalid parameters": "Invalid request parameters.",
9
-    "login server error": "The login server returned an error: {arg}",
10
-    "no access permission": "You do not have permission to access this system."
6
+    "login server error": "The login server returned an error: {arg}"
11 7
 }

+ 8
- 0
langs/en/index.json View File

@@ -0,0 +1,8 @@
1
+{
2
+    "You have been logged out.": "You have been logged out.",
3
+    "Log in again": "Log in again",
4
+    "login server unavailable": "Login server unavailable.  Try again later or contact technical support.",
5
+    "no access permission": "You do not have permission to access this system.",
6
+    "Logged in": "Logged in",
7
+    "Continue": "Continue"
8
+}

Loading…
Cancel
Save