mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
[FEATURE] blobvault: resend email verification
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user