Browse Source

Add app icon to login flow

Skylar Ittner 1 month ago
parent
commit
2836a05f90

+ 6
- 1
api/actions/getloginkey.php View File

@@ -6,7 +6,12 @@
6 6
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 7
  */
8 8
 
9
-$code = LoginKey::generate($VARS['appname']);
9
+$appicon = null;
10
+if (!empty($VARS['appicon'])) {
11
+    $appicon = $VARS['appicon'];
12
+}
13
+
14
+$code = LoginKey::generate($VARS['appname'], $appicon);
10 15
 
11 16
 if (strpos($SETTINGS['url'], "http") === 0) {
12 17
     $url = $SETTINGS['url'] . "login/";

+ 2
- 1
api/apisettings.php View File

@@ -215,7 +215,8 @@ $APIS = [
215 215
     "getloginkey" => [
216 216
         "load" => "getloginkey.php",
217 217
         "vars" => [
218
-            "appname" => "string"
218
+            "appname" => "string",
219
+            "appicon (optional)" => "string"
219 220
         ]
220 221
     ],
221 222
     "checkloginkey" => [

BIN
database.mwb View File


+ 2
- 1
database_upgrade/2.1_3.0.sql View File

@@ -25,4 +25,5 @@ ENGINE = InnoDB
25 25
 DEFAULT CHARACTER SET = utf8;
26 26
 
27 27
 ALTER TABLE `userloginkeys`
28
-ADD COLUMN `appname` VARCHAR(255) NOT NULL AFTER `uid`;
28
+ADD COLUMN `appname` VARCHAR(255) NOT NULL AFTER `uid`;
29
+ADD COLUMN `appicon` TINYTEXT NULL DEFAULT NULL AFTER `appname`;

+ 6
- 8
index.php View File

@@ -26,16 +26,14 @@ if (!empty($_GET['logout'])) {
26 26
 
27 27
     <link href="static/css/bootstrap.min.css" rel="stylesheet">
28 28
     <link href="static/css/svg-with-js.min.css" rel="stylesheet">
29
-    <style nonce="<?php echo $SECURE_NONCE; ?>">
30
-        .display-5 {
31
-            font-size: 3rem;
32
-            font-weight: 300;
33
-            line-height: 1.2;
34
-        }
35
-    </style>
29
+    <link href="static/css/login.css" rel="stylesheet">
36 30
 
37 31
     <div class="container mt-4">
38 32
         <div class="row justify-content-center">
33
+            <div class="col-12 text-center">
34
+                <img class="banner-image" src="./static/img/logo.svg" />
35
+            </div>
36
+
39 37
             <div class="col-12 text-center">
40 38
                 <h1 class="display-5 mb-4"><?php $Strings->get("You have been logged out.") ?></h1>
41 39
             </div>
@@ -73,7 +71,7 @@ if (empty($_SESSION["login_code"])) {
73 71
 
74 72
 if ($redirecttologin) {
75 73
     try {
76
-        $code = LoginKey::generate($SETTINGS["site_title"]);
74
+        $code = LoginKey::generate($SETTINGS["site_title"], "../static/img/logo.svg");
77 75
 
78 76
         $_SESSION["login_code"] = $code;
79 77
 

+ 2
- 2
lib/LoginKeys.lib.php View File

@@ -8,13 +8,13 @@
8 8
 
9 9
 class LoginKey {
10 10
 
11
-    public static function generate(string $appname): string {
11
+    public static function generate(string $appname, $appicon = null): string {
12 12
         global $database;
13 13
         do {
14 14
             $code = base64_encode(random_bytes(32));
15 15
         } while ($database->has('userloginkeys', ['key' => $code]));
16 16
 
17
-        $database->insert('userloginkeys', ['key' => $code, 'expires' => date("Y-m-d H:i:s", time() + 600), 'appname' => $appname]);
17
+        $database->insert('userloginkeys', ['key' => $code, 'expires' => date("Y-m-d H:i:s", time() + 600), 'appname' => $appname, 'appicon' => $appicon]);
18 18
 
19 19
         return $code;
20 20
     }

+ 3
- 1
login/index.php View File

@@ -21,7 +21,9 @@ if (!$database->has("userloginkeys", ["AND" => ["key" => $_GET["code"]], "expire
21 21
     die("Invalid auth code.");
22 22
 }
23 23
 
24
-$APPNAME = $database->get("userloginkeys", "appname", ["key" => $_GET["code"]]);
24
+$APPINFO = $database->get("userloginkeys", ["appname", "appicon"], ["key" => $_GET["code"]]);
25
+$APPNAME = $APPINFO["appname"];
26
+$APPICON = $APPINFO["appicon"];
25 27
 
26 28
 if (empty($_SESSION['thisstep'])) {
27 29
     $_SESSION['thisstep'] = "username";

+ 15
- 0
login/parts/header.php View File

@@ -26,6 +26,21 @@ header("Link: <../static/js/fontawesome-all.min.js>; rel=preload; as=script", fa
26 26
 
27 27
 <div class="container mt-4">
28 28
     <div class="row justify-content-center">
29
+        <?php
30
+        if (!empty($APPICON)) {
31
+            ?>
32
+            <div class="col-12 text-center">
33
+                <img class="banner-image" src="<?php echo $APPICON; ?>" />
34
+            </div>
35
+            <?php
36
+        } else {
37
+            ?>
38
+        <div class="col-12">
39
+            <div class="blank-image"></div>
40
+        </div>
41
+        <?php
42
+        }
43
+        ?>
29 44
         <div class="col-12 text-center">
30 45
             <h1 class="display-5 mb-4"><?php $Strings->build("Login to {app}", ["app" => htmlentities($APPNAME)]); ?></h1>
31 46
         </div>

+ 13
- 1
static/css/login.css View File

@@ -5,7 +5,19 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 5
 */
6 6
 
7 7
 .display-5 {
8
-    font-size: 3rem;
8
+    font-size: 2.5rem;
9 9
     font-weight: 300;
10 10
     line-height: 1.2;
11
+}
12
+
13
+.banner-image {
14
+    max-height: 100px;
15
+    margin: 2em auto;
16
+    border: 1px solid grey;
17
+    border-radius: 15%;
18
+}
19
+
20
+.blank-image {
21
+    height: 100px;
22
+    margin: 2em auto;
11 23
 }

Loading…
Cancel
Save