From ff6f9f7c63999d51170d2f5b8424223003ea02ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Obernd=C3=B6rfer?= Date: Mon, 17 Jun 2019 16:15:07 +0200 Subject: [PATCH] Add views for key search result, verify success and removal success pages. --- locales/de.json | 6 ++++-- locales/en.json | 8 +++++--- src/app/index.js | 13 +++++++++++-- src/route/hkp.js | 10 +++++++--- src/route/rest.js | 9 ++++----- src/service/public-key.js | 4 +++- src/view/footer.html | 9 +++++++++ src/view/index.html | 12 ++---------- src/view/key-armored.html | 23 +++++++++++++++++++++++ src/view/layout.html | 4 ++-- src/view/manage.html | 12 ++---------- src/view/removal-success.html | 15 +++++++++++++++ src/view/verify-success.html | 16 ++++++++++++++++ 13 files changed, 103 insertions(+), 38 deletions(-) create mode 100644 src/view/footer.html create mode 100644 src/view/key-armored.html create mode 100644 src/view/removal-success.html create mode 100644 src/view/verify-success.html diff --git a/locales/de.json b/locales/de.json index 08e32d8..518157a 100644 --- a/locales/de.json +++ b/locales/de.json @@ -2,7 +2,9 @@ "key_not_found": "Schlüssel nicht gefunden", "verify_key_subject": "Bestätigen Sie Ihre E-Mail-Adresse", "verify_key_text": "Hallo {0},\n\nbitte bestätigen Sie Ihre E-Mail-Adresse {1}.\nKlicken Sie hierzu auf den folgenden Link:\n\n{2}\n\nNach der Bestätigung Ihrer E-Mail-Adresse ist ihr öffentlicher Schlüssel in unserem Schlüssel Verzeichnis verfügbar.\n\nWeitere Informationen finden Sie unter {3}.\n\nIhr Mailvelope Team", - "verify_success": "

Mailvelope Key Server keys.mailvelope.com

E-Mail Adresse {0} erfolgreich verifiziert!

Ihr öffentlicher OpenPGP Schlüssel ist ab jetzt unter folgendem Link verfügbar: {1}

", + "verify_success_header": "E-Mail Adresse {0} erfolgreich verifiziert", + "verify_success_link": "Ihr öffentlicher OpenPGP Schlüssel ist ab jetzt unter folgendem Link verfügbar:", "verify_removal_subject": "Entfernen Ihres Schlüssels bestätigen", - "verify_removal_text": "Hallo {0},\n\nbitte bestätigen Sie das Entfernen Ihrer E-Mail-Adresse {1} von unserem Key Server ({2}).\nKlicken Sie hierzu auf den folgenden Link:\n\n{3}\n\nIhr Mailvelope Team" + "verify_removal_text": "Hallo {0},\n\nbitte bestätigen Sie das Entfernen Ihrer E-Mail-Adresse {1} von unserem Key Server ({2}).\nKlicken Sie hierzu auf den folgenden Link:\n\n{3}\n\nIhr Mailvelope Team", + "removal_success": "E-Mail Adresse {0} aus dem Schlüssel Verzeichnis entfernt" } diff --git a/locales/en.json b/locales/en.json index a78102d..a5599c4 100644 --- a/locales/en.json +++ b/locales/en.json @@ -1,8 +1,10 @@ { "key_not_found": "Key not found", "verify_key_subject": "Verify your email address", - "verify_key_text": "Hello {0},\n\nplease verify your email address {1} by clicking on the following link:\n\n{2}\n\nAfter verification of your email address your public key is available in our key directory.\n\nYou can find more info at {3}.\n\nGreetings from the Mailvelope Team", - "verify_success": "

Mailvelope Key Server keys.mailvelope.com

Email address {0} successfully verified!

Your public OpenPGP key is now available at the following link: {1}

", + "verify_key_text": "Hello {0},\n\nplease verify your email address {1} by clicking on the following link:\n\n{2}\n\nAfter verification of your email address, your public key is available in our key directory.\n\nYou can find more info at {3}.\n\nGreetings from the Mailvelope Team", + "verify_success_header": "Email address {0} successfully verified", + "verify_success_link": "Your public OpenPGP key is now available at the following link:", "verify_removal_subject": "Verify key removal", - "verify_removal_text": "Hello {0},\n\nplease verify removal of your email address {1} from our key server ({2}) by clicking on the following link:\n\n{3}\n\nGreetings from the Mailvelope Team" + "verify_removal_text": "Hello {0},\n\nplease verify removal of your email address {1} from our key server ({2}) by clicking on the following link:\n\n{3}\n\nGreetings from the Mailvelope Team", + "removal_success": "Email address {0} removed from the key directory" } diff --git a/src/app/index.js b/src/app/index.js index 35527f0..ae9d34c 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -23,6 +23,7 @@ const router = require('koa-router')(); const render = require('koa-ejs'); const locales = require('koa-locales'); const config = require('config'); +const path = require('path'); const middleware = require('./middleware'); const Mongo = require('../dao/mongo'); const Email = require('../email/email'); @@ -32,14 +33,22 @@ const PGP = require('../service/pgp'); const PublicKey = require('../service/public-key'); const app = new Koa(); + render(app, { - root: `${__dirname}/../view` + root: path.join(__dirname, '../view') }); + locales(app); let hkp; let rest; +app.use(async (ctx, next) => { + ctx.state = ctx.state || {}; + ctx.state.__ = ctx.__.bind(ctx); + await next(); +}); + // UI views router.get('/', ctx => ctx.render('index')); router.redirect('/index.html', '/'); @@ -58,7 +67,7 @@ app.use(middleware.upgradeToHTTPS); app.use(middleware.setHTTPResponseHeaders); app.use(router.routes()); app.use(router.allowedMethods()); -app.use(serve(`${__dirname}/../static`)); +app.use(serve(path.join(__dirname, '../static'))); async function init() { // inject dependencies diff --git a/src/route/hkp.js b/src/route/hkp.js index 060cb5c..dcf7a4a 100644 --- a/src/route/hkp.js +++ b/src/route/hkp.js @@ -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 diff --git a/src/route/rest.js b/src/route/rest.js index 84fb75a..627d75c 100644 --- a/src/route/rest.js +++ b/src/route/rest.js @@ -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}); } } diff --git a/src/service/public-key.js b/src/service/public-key.js index 8e9c69a..36efcde 100644 --- a/src/service/public-key.js +++ b/src/service/public-key.js @@ -378,7 +378,8 @@ class PublicKey { } if (flagged.userIds.length === 1) { // delete the key - return this._mongo.remove({keyId}, DB_TYPE); + await this._mongo.remove({keyId}, DB_TYPE); + return flagged.userIds[0]; } // update the key const rmIdx = flagged.userIds.findIndex(userId => userId.nonce === nonce); @@ -392,6 +393,7 @@ class PublicKey { } flagged.userIds.splice(rmIdx, 1); await this._mongo.update({keyId}, flagged, DB_TYPE); + return rmUserId; } } diff --git a/src/view/footer.html b/src/view/footer.html new file mode 100644 index 0000000..4da4802 --- /dev/null +++ b/src/view/footer.html @@ -0,0 +1,9 @@ + diff --git a/src/view/index.html b/src/view/index.html index 836a682..e20b4be 100644 --- a/src/view/index.html +++ b/src/view/index.html @@ -4,7 +4,7 @@ @@ -41,14 +41,6 @@ - + <%- include('footer') %> diff --git a/src/view/key-armored.html b/src/view/key-armored.html new file mode 100644 index 0000000..cbd71bc --- /dev/null +++ b/src/view/key-armored.html @@ -0,0 +1,23 @@ +
+ +
+ +

Mailvelope Key Server

+
+ +
+
+

<%= query.email ? `Email: ${query.email}` : query.fingerprint ? `Fingerprint: ${query.fingerprint}` : `Key ID: ${query.keyId}` %>

+
<%= key.publicKeyArmored %>
+
+
+ + <%- include('footer') %> + +
diff --git a/src/view/layout.html b/src/view/layout.html index 56e9c82..8801c7b 100644 --- a/src/view/layout.html +++ b/src/view/layout.html @@ -6,8 +6,8 @@ Mailvelope Key Server - - + + <%- body %> diff --git a/src/view/manage.html b/src/view/manage.html index 6e5adcc..203f913 100644 --- a/src/view/manage.html +++ b/src/view/manage.html @@ -4,7 +4,7 @@ @@ -72,15 +72,7 @@ - + <%- include('footer') %> diff --git a/src/view/removal-success.html b/src/view/removal-success.html new file mode 100644 index 0000000..0f4cf59 --- /dev/null +++ b/src/view/removal-success.html @@ -0,0 +1,15 @@ +
+ +
+

Mailvelope Key Server

+
+ +
+
+

<%= __('removal_success', [email]) %>

+
+
+ + <%- include('footer') %> + +
diff --git a/src/view/verify-success.html b/src/view/verify-success.html new file mode 100644 index 0000000..6790e48 --- /dev/null +++ b/src/view/verify-success.html @@ -0,0 +1,16 @@ +
+ +
+

Mailvelope Key Server

+
+ +
+
+

<%= __('verify_success_header', [email]) %>

+

<%= __('verify_success_link') %> <%= link %>

+
+
+ + <%- include('footer') %> + +