Implement Email DAO for sending verification mails

This commit is contained in:
Tankred Hase
2016-05-29 16:47:45 +02:00
parent c805371f0e
commit d3cce89b06
10 changed files with 235 additions and 24 deletions

View File

@@ -50,13 +50,14 @@ class PublicKey {
/**
* Persist a new public key
* @param {String} options.publicKeyArmored The ascii armored pgp key block
* @param {String} options.primaryEmail (optional) The key's primary email address
* @param {String} publicKeyArmored The ascii armored pgp key block
* @param {String} primaryEmail (optional) The key's primary email address
* @param {Object} origin Required for links to the keyserver e.g. { protocol:'https', host:'openpgpkeys@example.com' }
* @yield {undefined}
*/
*put(options) {
// parse key block
let publicKeyArmored = options.publicKeyArmored;
let publicKeyArmored = options.publicKeyArmored, primaryEmail = options.primaryEmail, origin = options.origin;
let params = this.parseKey(publicKeyArmored);
// check for existing verfied key by id or email addresses
let verified = yield this._userid.getVerfied(params);
@@ -73,7 +74,7 @@ class PublicKey {
// persist new user ids
let userIds = yield this._userid.batch(params);
// send mails to verify user ids (send only one if primary email is provided)
yield this._email.sendVerification({ userIds, primaryEmail:options.primaryEmail });
yield this._email.sendVerification({ userIds, primaryEmail, origin });
}
/**

View File

@@ -107,4 +107,19 @@ exports.throw = function(status, message) {
err.status = status;
err.expose = true; // display message to the client
throw err;
};
/**
* Get the server's own origin host and protocol. Required for sending
* verification links via email. If the PORT environmane variable
* is set, we assume the protocol to be 'https', since the AWS loadbalancer
* speaks 'https' externally but 'http' between the LB and the server.
* @param {Object} ctx The koa request/repsonse context
* @return {Object} The server origin
*/
exports.getOrigin = function(ctx) {
return {
protocol: process.env.PORT ? 'https' : ctx.protocol,
host: ctx.host
};
};