Clear local storage on logout
This commit is contained in:
parent
cf950efb84
commit
8bdebd543d
@ -140,11 +140,14 @@ Config.LangCountries = {"es": "ES", "ru": "RU", "en": "US", "de": "DE", "it": "I
|
||||
return keyPrefix;
|
||||
}
|
||||
|
||||
function storageGetValue() {
|
||||
var keys = Array.prototype.slice.call(arguments),
|
||||
callback = keys.pop(),
|
||||
result = [],
|
||||
single = keys.length == 1,
|
||||
function storageGetValue(keys, callback) {
|
||||
var single = false;
|
||||
if (!Array.isArray(keys)) {
|
||||
keys = Array.prototype.slice.call(arguments);
|
||||
callback = keys.pop();
|
||||
single = keys.length == 1;
|
||||
}
|
||||
var result = [],
|
||||
value,
|
||||
allFound = true,
|
||||
prefix = storageGetPrefix(),
|
||||
@ -227,14 +230,16 @@ Config.LangCountries = {"es": "ES", "ru": "RU", "en": "US", "de": "DE", "it": "I
|
||||
chrome.storage.local.set(keyValues, callback);
|
||||
};
|
||||
|
||||
function storageRemoveValue () {
|
||||
var keys = Array.prototype.slice.call(arguments),
|
||||
prefix = storageGetPrefix(),
|
||||
i, key, callback;
|
||||
|
||||
if (typeof keys[keys.length - 1] === 'function') {
|
||||
callback = keys.pop();
|
||||
function storageRemoveValue (keys, callback) {
|
||||
if (!Array.isArray(keys)) {
|
||||
keys = Array.prototype.slice.call(arguments);
|
||||
if (typeof keys[keys.length - 1] === 'function') {
|
||||
callback = keys.pop();
|
||||
}
|
||||
}
|
||||
var prefix = storageGetPrefix(),
|
||||
i, key;
|
||||
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
key = keys[i] = prefix + keys[i];
|
||||
@ -255,12 +260,33 @@ Config.LangCountries = {"es": "ES", "ru": "RU", "en": "US", "de": "DE", "it": "I
|
||||
}
|
||||
};
|
||||
|
||||
function storageClear(callback) {
|
||||
if (useLs) {
|
||||
try {
|
||||
localStorage.clear();
|
||||
} catch (e) {
|
||||
useLs = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (useCs) {
|
||||
chrome.storage.local.clear(function () {
|
||||
cache = {};
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
cache = {};
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
window.ConfigStorage = {
|
||||
prefix: storageSetPrefix,
|
||||
noPrefix: storageSetNoPrefix,
|
||||
get: storageGetValue,
|
||||
set: storageSetValue,
|
||||
remove: storageRemoveValue
|
||||
remove: storageRemoveValue,
|
||||
clear: storageClear
|
||||
};
|
||||
|
||||
})(this);
|
||||
|
@ -47,7 +47,7 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
|
||||
for (var dcID = 1; dcID <= 5; dcID++) {
|
||||
storageKeys.push('dc' + dcID + '_auth_key');
|
||||
}
|
||||
return Storage.get.apply(Storage, storageKeys).then(function (storageResult) {
|
||||
return Storage.get(storageKeys).then(function (storageResult) {
|
||||
var logoutPromises = [];
|
||||
for (var i = 0; i < storageResult.length; i++) {
|
||||
if (storageResult[i]) {
|
||||
@ -58,12 +58,36 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
|
||||
Storage.remove('dc', 'user_auth');
|
||||
baseDcID = false;
|
||||
telegramMeNotify(false);
|
||||
return mtpClearStorage();
|
||||
}, function (error) {
|
||||
Storage.remove.apply(storageKeys);
|
||||
Storage.remove('dc', 'user_auth');
|
||||
storageKeys.push('dc', 'user_auth');
|
||||
Storage.remove(storageKeys);
|
||||
baseDcID = false;
|
||||
error.handled = true;
|
||||
telegramMeNotify(false);
|
||||
return mtpClearStorage();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function mtpClearStorage() {
|
||||
var saveKeys = [];
|
||||
for (var dcID = 1; dcID <= 5; dcID++) {
|
||||
saveKeys.push('dc' + dcID + '_auth_key');
|
||||
saveKeys.push('t_dc' + dcID + '_auth_key');
|
||||
}
|
||||
Storage.noPrefix();
|
||||
Storage.get(saveKeys).then(function (values) {
|
||||
Storage.clear().then(function () {
|
||||
var restoreObj = {};
|
||||
angular.forEach(saveKeys, function (key, i) {
|
||||
var value = values[i];
|
||||
if (value !== false && value !== undefined) {
|
||||
restoreObj[key] = value;
|
||||
}
|
||||
});
|
||||
Storage.noPrefix();
|
||||
return Storage.set(restoreObj);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -95,6 +119,9 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
|
||||
serverSaltHex = result[1];
|
||||
// console.log('ass', dcID, authKeyHex, serverSaltHex);
|
||||
if (authKeyHex && authKeyHex.length == 512) {
|
||||
if (!serverSaltHex || serverSaltHex.length != 16) {
|
||||
serverSaltHex = 'AAAAAAAAAAAAAAAA';
|
||||
}
|
||||
var authKey = bytesFromHex(authKeyHex);
|
||||
var serverSalt = bytesFromHex(serverSaltHex);
|
||||
|
||||
|
@ -15,7 +15,7 @@ angular.module('izhukov.utils', [])
|
||||
|
||||
this.$get = ['$q', function ($q) {
|
||||
var methods = {};
|
||||
angular.forEach(['get', 'set', 'remove'], function (methodName) {
|
||||
angular.forEach(['get', 'set', 'remove', 'clear'], function (methodName) {
|
||||
methods[methodName] = function () {
|
||||
var deferred = $q.defer(),
|
||||
args = Array.prototype.slice.call(arguments);
|
||||
@ -28,6 +28,11 @@ angular.module('izhukov.utils', [])
|
||||
return deferred.promise;
|
||||
};
|
||||
});
|
||||
|
||||
methods.noPrefix = function () {
|
||||
ConfigStorage.noPrefix();
|
||||
};
|
||||
|
||||
return methods;
|
||||
}];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user