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"),
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);
}

View file

@ -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;

View file

@ -12,6 +12,7 @@
<h1 id="profileName"></h1>
<div class="content">
<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>