Add views for key search result, verify success and removal success pages.

This commit is contained in:
Thomas Oberndörfer
2019-06-17 16:15:07 +02:00
parent f399da9614
commit ff6f9f7c63
13 changed files with 103 additions and 38 deletions

View File

@@ -56,7 +56,7 @@ class HKP {
const params = this.parseQueryString(ctx);
const key = await this._publicKey.get(params, ctx);
this.setGetHeaders(ctx, params);
this.setGetBody(ctx, params, key);
await this.setGetBody(ctx, params, key);
}
/**
@@ -119,9 +119,13 @@ class HKP {
* @param {Object} params The parsed query string parameters
* @param {Object} key The public key document
*/
setGetBody(ctx, params, key) {
async setGetBody(ctx, params, key) {
if (params.op === 'get') {
ctx.body = key.publicKeyArmored;
if (params.mr) {
ctx.body = key.publicKeyArmored;
} else {
await ctx.render('key-armored', {query: params, key});
}
} else if (['index', 'vindex'].indexOf(params.op) !== -1) {
const VERSION = 1;
const COUNT = 1; // number of keys

View File

@@ -62,7 +62,7 @@ class REST {
if (!util.isKeyId(q.keyId) && !util.isFingerPrint(q.fingerprint) && !util.isEmail(q.email)) {
ctx.throw(400, 'Invalid request!');
}
ctx.body = await this._publicKey.get(q, ctx);
await ctx.render('key-armored', {query: q, key: await this._publicKey.get(q, ctx)});
}
/**
@@ -77,8 +77,7 @@ class REST {
const {email} = await this._publicKey.verify(q);
// create link for sharing
const link = util.url(util.origin(ctx), `/pks/lookup?op=get&search=${email}`);
ctx.body = ctx.__('verify_success', [email, link]);
ctx.set('Content-Type', 'text/html; charset=utf-8');
await ctx.render('verify-success', {email, link});
}
/**
@@ -104,8 +103,8 @@ class REST {
if (!util.isKeyId(q.keyId) || !util.isString(q.nonce)) {
ctx.throw(400, 'Invalid request!');
}
await this._publicKey.verifyRemove(q);
ctx.body = 'Email address successfully removed!';
const {email} = await this._publicKey.verifyRemove(q);
await ctx.render('removal-success', {email});
}
}