Token Caching now works

This commit is contained in:
Amish Shah
2015-12-14 18:06:03 +00:00
parent a122f0994e
commit 8f5722d242
7 changed files with 71 additions and 26 deletions

View File

@@ -41,10 +41,9 @@ var TokenCacher = (function (_EventEmitter) {
TokenCacher.prototype.setToken = function setToken(email, password, token) {
console.log("wanting to cache", token);
token = new Buffer(token).toString("base64");
var cipher = _crypto2["default"].createCipher(algo, password);
var crypted = cipher.update(token, 'utf8', 'base64');
crypted += cipher.final('base64');
var crypted = cipher.update("valid" + token, 'utf8', 'hex');
crypted += cipher.final('hex');
this.data[email] = crypted;
this.save();
};
@@ -59,10 +58,11 @@ var TokenCacher = (function (_EventEmitter) {
try {
var decipher = _crypto2["default"].createDecipher(algo, password);
var dec = decipher.update(this.data[email], "base64", 'utf8');
var dec = decipher.update(this.data[email], "hex", 'utf8');
dec += decipher.final('utf8');
return new Buffer(dec, "base64").toString("ascii");
return dec.indexOf("valid") === 0 ? dec.substr(5) : false;
} catch (e) {
console.log(e);
return null;
}
} else {