Allow overriding of profile mode

This commit is contained in:
Yarmo Mackenbach 2020-06-29 00:09:31 +02:00
parent d8a5a0dd4a
commit f451619fda
3 changed files with 47 additions and 13 deletions

View file

@ -492,7 +492,8 @@ async function fetchKeys(opts) {
let elFormVerify = document.body.querySelector("#form-verify"), let elFormVerify = document.body.querySelector("#form-verify"),
elFormEncrypt = document.body.querySelector("#form-encrypt"), elFormEncrypt = document.body.querySelector("#form-encrypt"),
elFormProofs = document.body.querySelector("#form-proofs"), elFormProofs = document.body.querySelector("#form-proofs"),
elProfileUid = document.body.querySelector("#profileUid"); elProfileUid = document.body.querySelector("#profileUid"),
elProfileMode = document.body.querySelector("#profileMode");
if (elFormVerify) { if (elFormVerify) {
elFormVerify.onsubmit = function (evt) { elFormVerify.onsubmit = function (evt) {
@ -583,18 +584,31 @@ if (elFormProofs) {
if (elProfileUid) { if (elProfileUid) {
let match, opts, profileUid = elProfileUid.innerHTML; let match, opts, profileUid = elProfileUid.innerHTML;
if (/.*@.*/.test(profileUid)) { switch (elProfileMode.innerHTML) {
// Match email for wkd default:
opts = { case "auto":
input: profileUid, if (/.*@.*/.test(profileUid)) {
mode: "wkd" // Match email for wkd
} opts = {
} else { input: profileUid,
// Match fingerprint for hkp mode: "wkd"
opts = { }
input: profileUid, } else {
mode: "hkp" // Match fingerprint for hkp
} opts = {
input: profileUid,
mode: "hkp"
}
}
break;
case: "hkp":
case: "wkd":
opts = {
input: profileUid,
mode: elProfileMode.innerHTML
}
break;
} }
displayProfile(opts); displayProfile(opts);
} }

View file

@ -25,6 +25,8 @@ $router->map('GET', '/guides', function() {}, 'guides');
$router->map('GET', '/guides/[:id]', function() {}, 'guideId'); $router->map('GET', '/guides/[:id]', function() {}, 'guideId');
$router->map('GET', '/faq', function() {}, 'faq'); $router->map('GET', '/faq', function() {}, 'faq');
$router->map('GET', '/[**:uid]', function() {}, 'profile'); $router->map('GET', '/[**:uid]', function() {}, 'profile');
$router->map('GET', '/hkp/[**:uid]', function() {}, 'profile/HKP');
$router->map('GET', '/wkd/[**:uid]', function() {}, 'profileWKD');
// Router matching // Router matching
$match = $router->match(); $match = $router->match();
@ -93,6 +95,23 @@ if(is_array($match) && is_callable($match['target'])) {
case 'profile': case 'profile':
$content = file_get_contents('pages/profile.html'); $content = file_get_contents('pages/profile.html');
$content = str_replace('%UID%', $match['params']['uid'], $content); $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'); header('Content-Type: text/html; charset=utf-8');
echo($content); echo($content);
break; break;

View file

@ -12,6 +12,7 @@
<h1 id="profileName"></h1> <h1 id="profileName"></h1>
<div class="content"> <div class="content">
<span id="profileUid" style="display: none;">%UID%</span> <span id="profileUid" style="display: none;">%UID%</span>
<span id="profileMode" style="display: none;">%MODE%</span>
<div id="profileData"><p>Loading keys &amp; verifying proofs&hellip;</p></div> <div id="profileData"><p>Loading keys &amp; verifying proofs&hellip;</p></div>
</div> </div>