From 77e69efe19770f496f515badef3b48a2a2bd597d Mon Sep 17 00:00:00 2001 From: Matthew Fettig Date: Wed, 4 Jun 2014 15:09:22 -0700 Subject: [PATCH] [FEATURE] blobvault: resend email verification --- src/js/ripple/blob.js | 42 +++++++++++++++++++++++++++++++++--- src/js/ripple/vaultclient.js | 38 ++++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 10 deletions(-) diff --git a/src/js/ripple/blob.js b/src/js/ripple/blob.js index 64c1e30f..45ddd6e7 100644 --- a/src/js/ripple/blob.js +++ b/src/js/ripple/blob.js @@ -829,16 +829,52 @@ BlobClient.get = function (url, id, crypt, fn) { BlobClient.verify = function(url, username, token, fn) { url += '/v1/user/' + username + '/verify/' + token; request.get(url, function(err, resp){ - if (err) { - fn(err); + if (err) { + fn(new Error("Failed to verify the account - XHR error")); } else if (resp.body && resp.body.result === 'success') { - fn(null, data); + fn(null, resp.body); } else { fn(new Error('Failed to verify the account')); } }); }; +/** + * ResendEmail + * resend verification email + */ +BlobClient.resendEmail = function (opts, fn) { + var config = { + method : 'POST', + url : opts.url + '/v1/user/email', + data : { + blob_id : opts.id, + username : opts.username, + email : opts.email, + hostlink : opts.activateLink + } + }; + + var signedRequest = new SignedRequest(config); + var signed = signedRequest.signAsymmetric(opts.masterkey, opts.account_id, opts.id); + + request.post(signed.url) + .send(signed.data) + .end(function(err, resp) { + if (err) { + console.log("blob: could not resend the token:", err); + fn(new Error("Failed to resend the token")); + } else if (resp.body && resp.body.result === 'success') { + fn(null, resp.body); + } else if (resp.body && resp.body.result === 'error') { + console.log("blob: could not resend the token:", resp.body.message); + fn(new Error("Failed to resend the token")); + } else { + fn(new Error("Failed to resend the token")); + } + }); +}; + /** * Create a blob object * diff --git a/src/js/ripple/vaultclient.js b/src/js/ripple/vaultclient.js index 922aa7d3..ffb8ae30 100644 --- a/src/js/ripple/vaultclient.js +++ b/src/js/ripple/vaultclient.js @@ -153,9 +153,16 @@ VaultClient.prototype.unlock = function(username, password, encryptSecret, callb return callback(err); } + var secret; + try { + secret = crypt.decrypt(keys.unlock, encryptSecret) + } catch (err) { + return callback(err); + } + callback(null, { - keys: keys, - secret: crypt.decrypt(keys.unlock, encryptSecret) + keys : keys, + secret : secret }); }); }; @@ -188,12 +195,19 @@ VaultClient.prototype.loginAndUnlock = function(username, password, callback) { return callback(err); } + var secret; + try { + secret = crypt.decrypt(keys.unlock, blob.encrypted_secret) + } catch (err) { + return callback(err); + } + callback(null, { - blob: blob, - unlock: keys.unlock, - secret: crypt.decrypt(keys.unlock, blob.encrypted_secret), - username: authInfo.username, - verified: authInfo.emailVerified + blob : blob, + unlock : keys.unlock, + secret : secret, + username : authInfo.username, + verified : authInfo.emailVerified }); }); }; @@ -263,6 +277,16 @@ VaultClient.prototype.verify = function(username, token, callback) { }); }; +/** + * resendEmail + * send a new verification email + * @param {object} options + * @param {function} callback + */ +VaultClient.prototype.resendEmail = function (options, callback) { + blobClient.resendEmail(options, callback); +}; + /** * Register a new user and save to the blob vault *