Key upload and sending verification email works
This commit is contained in:
11
src/app.js
11
src/app.js
@@ -101,6 +101,17 @@ function injectDependencies() {
|
||||
password: process.env.MONGO_PASS || credentials.mongo.pass
|
||||
});
|
||||
email = new Email(nodemailer);
|
||||
email.init({
|
||||
host: process.env.SMTP_HOST || credentials.smtp.host,
|
||||
auth: {
|
||||
user: process.env.SMTP_USER || credentials.smtp.user,
|
||||
pass: process.env.SMTP_PASS || credentials.smtp.pass
|
||||
},
|
||||
sender: {
|
||||
name: process.env.SENDER_NAME || credentials.sender.name,
|
||||
email: process.env.SENDER_EMAIL || credentials.sender.email
|
||||
}
|
||||
});
|
||||
userId = new UserId(mongo);
|
||||
publicKey = new PublicKey(openpgp, mongo, email, userId);
|
||||
hkp = new HKP(publicKey);
|
||||
|
||||
@@ -46,6 +46,7 @@ class HKP {
|
||||
}
|
||||
let origin = util.getOrigin(ctx);
|
||||
yield this._publicKey.put({ publicKeyArmored, origin });
|
||||
ctx.status = 201;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,6 +47,7 @@ class REST {
|
||||
}
|
||||
let origin = util.getOrigin(ctx);
|
||||
yield this._publicKey({ publicKeyArmored, primaryEmail, origin });
|
||||
ctx.status = 201;
|
||||
}
|
||||
|
||||
*verify(ctx) {
|
||||
|
||||
@@ -62,7 +62,7 @@ class PublicKey {
|
||||
// check for existing verfied key by id or email addresses
|
||||
let verified = yield this._userid.getVerfied(params);
|
||||
if (verified) {
|
||||
util.throw(304, 'Key for this user already exists: ' + verified.stringify());
|
||||
util.throw(304, 'Key for this user already exists: ' + JSON.stringify(verified));
|
||||
}
|
||||
// delete old/unverified key and user ids with the same key id
|
||||
yield this.remove({ keyid:params.keyid });
|
||||
@@ -74,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, origin });
|
||||
yield this._email.sendVerifyKey({ userIds, primaryEmail, origin });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const uuid = require('node-uuid');
|
||||
|
||||
/**
|
||||
* Database documents have the format:
|
||||
* {
|
||||
@@ -51,11 +53,16 @@ class UserId {
|
||||
* @yield {Array} A list of user ids with generated nonces
|
||||
*/
|
||||
*batch(options) {
|
||||
options.userIds.forEach(u => u.keyid = options.keyid); // set keyid on docs
|
||||
let r = yield this._mongo.batch(options.userIds, DB_TYPE);
|
||||
if (r.insertedCount !== options.userIds.length) {
|
||||
let userIds = options.userIds, keyid = options.keyid;
|
||||
userIds.forEach(u => {
|
||||
u.keyid = keyid; // set keyid on docs
|
||||
u.nonce = uuid.v4(); // generate nonce for verification
|
||||
});
|
||||
let r = yield this._mongo.batch(userIds, DB_TYPE);
|
||||
if (r.insertedCount !== userIds.length) {
|
||||
throw new Error('Failed to persist user ids');
|
||||
}
|
||||
return userIds;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user