Key upload and sending verification email works

This commit is contained in:
Tankred Hase
2016-05-29 18:59:14 +02:00
parent 3a6842c296
commit e2695aecc7
8 changed files with 43 additions and 12 deletions

View File

@@ -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 });
}
/**

View File

@@ -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;
}
/**