From f451619fdabc0174ff6a77e62dcbdd840309e5a7 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Mon, 29 Jun 2020 00:09:31 +0200 Subject: [PATCH] Allow overriding of profile mode --- assets/scripts.js | 40 +++++++++++++++++++++++++++------------- index.php | 19 +++++++++++++++++++ pages/profile.html | 1 + 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/assets/scripts.js b/assets/scripts.js index e1a4b50..5889297 100644 --- a/assets/scripts.js +++ b/assets/scripts.js @@ -492,7 +492,8 @@ async function fetchKeys(opts) { let elFormVerify = document.body.querySelector("#form-verify"), elFormEncrypt = document.body.querySelector("#form-encrypt"), elFormProofs = document.body.querySelector("#form-proofs"), - elProfileUid = document.body.querySelector("#profileUid"); + elProfileUid = document.body.querySelector("#profileUid"), + elProfileMode = document.body.querySelector("#profileMode"); if (elFormVerify) { elFormVerify.onsubmit = function (evt) { @@ -583,18 +584,31 @@ if (elFormProofs) { if (elProfileUid) { let match, opts, profileUid = elProfileUid.innerHTML; - if (/.*@.*/.test(profileUid)) { - // Match email for wkd - opts = { - input: profileUid, - mode: "wkd" - } - } else { - // Match fingerprint for hkp - opts = { - input: profileUid, - mode: "hkp" - } + switch (elProfileMode.innerHTML) { + default: + case "auto": + if (/.*@.*/.test(profileUid)) { + // Match email for wkd + opts = { + input: profileUid, + mode: "wkd" + } + } else { + // Match fingerprint for hkp + opts = { + input: profileUid, + mode: "hkp" + } + } + break; + + case: "hkp": + case: "wkd": + opts = { + input: profileUid, + mode: elProfileMode.innerHTML + } + break; } displayProfile(opts); } diff --git a/index.php b/index.php index 9592bf3..64c8204 100644 --- a/index.php +++ b/index.php @@ -25,6 +25,8 @@ $router->map('GET', '/guides', function() {}, 'guides'); $router->map('GET', '/guides/[:id]', function() {}, 'guideId'); $router->map('GET', '/faq', function() {}, 'faq'); $router->map('GET', '/[**:uid]', function() {}, 'profile'); +$router->map('GET', '/hkp/[**:uid]', function() {}, 'profile/HKP'); +$router->map('GET', '/wkd/[**:uid]', function() {}, 'profileWKD'); // Router matching $match = $router->match(); @@ -93,6 +95,23 @@ if(is_array($match) && is_callable($match['target'])) { case 'profile': $content = file_get_contents('pages/profile.html'); $content = str_replace('%UID%', $match['params']['uid'], $content); + $content = str_replace('%MODE%', "auto", $content); + header('Content-Type: text/html; charset=utf-8'); + echo($content); + break; + + case 'profileHKP': + $content = file_get_contents('pages/profile.html'); + $content = str_replace('%UID%', $match['params']['uid'], $content); + $content = str_replace('%MODE%', "hkp", $content); + header('Content-Type: text/html; charset=utf-8'); + echo($content); + break; + + case 'profileWKD': + $content = file_get_contents('pages/profile.html'); + $content = str_replace('%UID%', $match['params']['uid'], $content); + $content = str_replace('%MODE%', "wkd", $content); header('Content-Type: text/html; charset=utf-8'); echo($content); break; diff --git a/pages/profile.html b/pages/profile.html index 6b2d368..ed2541f 100644 --- a/pages/profile.html +++ b/pages/profile.html @@ -12,6 +12,7 @@

+

Loading keys & verifying proofs…