added function for clearing cookies

This commit is contained in:
Sefa Ilkimen
2016-12-05 18:25:14 +01:00
parent 20e5bd0ee9
commit 4afb375971
4 changed files with 25 additions and 13 deletions
+4 -1
View File
@@ -106,7 +106,10 @@ var http = {
this.headers[header] = value;
},
setDataSerializer: function (serializer) {
this.dataSerializer = checkSerializer(serializer);
this.dataSerializer = checkSerializer(serializer);
},
clearCookies: function () {
return cookieHandler.clearCookies();
},
enableSSLPinning: function (enable, success, failure) {
return exec(success, failure, 'CordovaHttpPlugin', 'enableSSLPinning', [enable]);
+3
View File
@@ -44,6 +44,9 @@ function registerService(http) {
setDataSerializer: function (serializer) {
return http.setParamSerializer(serializer);
},
clearCookies: function () {
return http.clearCookies();
},
enableSSLPinning: function (enable) {
return makePromise(http.enableSSLPinning, [enable]);
},
+11 -2
View File
@@ -1,12 +1,17 @@
var pluginId = module.id.slice(0, module.id.indexOf('.'));
var ToughCookie = require(pluginId + '.tough-cookie');
var WebStorageCookieStore = require(pluginId + '.local-storage-store');
var store = new WebStorageCookieStore();
var storage = window.localStorage;
var storeKey = '__advancedHttpCookieStore__';
var store = new WebStorageCookieStore(storage, storeKey);
var cookieJar = new ToughCookie.CookieJar(store);
module.exports = {
setCookie: setCookie,
getCookie: getCookie
getCookie: getCookie,
clearCookies: clearCookies
}
function setCookie(url, cookieStr) {
@@ -17,3 +22,7 @@ function setCookie(url, cookieStr) {
function getCookie(url) {
return cookieJar.getCookieStringSync(url);
}
function clearCookies() {
window.localStorage.removeItem(storeKey);
}
+7 -10
View File
@@ -34,13 +34,10 @@ var pluginId = module.id.slice(0, module.id.indexOf('.'));
var ToughCookie = require(pluginId + '.tough-cookie');
var _ = require(pluginId + '.lodash');
var Cookie = ToughCookie.Cookie;
var STORE_KEY = '__cookieStore__';
function WebStorageCookieStore(storage) {
function WebStorageCookieStore(storage, storeKey) {
ToughCookie.Store.call(this);
this._storage = storage || window.localStorage;
this._storeKey = storeKey || '__cookieStore__';
this.synchronous = true;
}
@@ -50,7 +47,7 @@ WebStorageCookieStore.prototype.findCookie = function(domain, path, key, callbac
var store = this._readStore();
var cookie = _.get(store, [domain, path, key], null);
callback(null, Cookie.fromJSON(cookie));
callback(null, ToughCookie.Cookie.fromJSON(cookie));
};
WebStorageCookieStore.prototype.findCookies = function(domain, path, callback) {
@@ -83,7 +80,7 @@ WebStorageCookieStore.prototype.findCookies = function(domain, path, callback) {
});
cookies = cookies.map(function(cookie) {
return Cookie.fromJSON(cookie);
return ToughCookie.Cookie.fromJSON(cookie);
});
callback(null, cookies);
@@ -157,7 +154,7 @@ WebStorageCookieStore.prototype.getAllCookies = function(callback) {
});
cookies = cookies.map(function(cookie) {
Cookie.fromJSON(cookie)
return ToughCookie.Cookie.fromJSON(cookie);
});
cookies.sort(function(c1, c2) {
@@ -168,7 +165,7 @@ WebStorageCookieStore.prototype.getAllCookies = function(callback) {
};
WebStorageCookieStore.prototype._readStore = function() {
var json = this._storage.getItem(STORE_KEY);
var json = this._storage.getItem(this._storeKey);
if (json !== null) {
try {
@@ -180,7 +177,7 @@ WebStorageCookieStore.prototype._readStore = function() {
};
WebStorageCookieStore.prototype._writeStore = function(store) {
this._storage.setItem(STORE_KEY, JSON.stringify(store));
this._storage.setItem(this._storeKey, JSON.stringify(store));
};
module.exports = WebStorageCookieStore;