[FEATURE] blobvault: resend email verification

This commit is contained in:
Matthew Fettig
2014-06-04 15:09:22 -07:00
parent da8061ed52
commit 77e69efe19
2 changed files with 70 additions and 10 deletions

View File

@@ -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
*

View File

@@ -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
*