From ac7fbc9e7c2990928896bc0faf52b7593f762466 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Nov 2014 13:53:52 -0300 Subject: [PATCH] add validation header --- plugins/emailstore.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/plugins/emailstore.js b/plugins/emailstore.js index 2aec6bd..a54bf4e 100644 --- a/plugins/emailstore.js +++ b/plugins/emailstore.js @@ -443,6 +443,20 @@ }; }; + + emailPlugin.addNeedValidationHeader = function(response, email, callback) { + emailPlugin.db.get(validatedKey(email), function(err, value) { + if (err && !err.notFound) + return callback(err); + + if (value) + return callback(); + + response.set('X-Email-Needs-Validation', 'true'); + return callback(null, value || false); + }); + }; + /** * Retrieve a record from the database */ @@ -460,10 +474,15 @@ } emailPlugin.retrieveDataByEmailAndPassphrase(email, key, passphrase, function(err, value) { - if (err) { + if (err) return emailPlugin.returnError(err, response); - } - response.send(value).end(); + + emailPlugin.addNeedValidationHeader(response, email, function(err) { + if (err) + return emailPlugin.returnError(err, response); + + response.send(value).end(); + }); }); };