forked from tableau/wdclib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ApprovedOrigins.js
40 lines (33 loc) · 1.18 KB
/
ApprovedOrigins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var APPROVED_ORIGINS_KEY = "wdc_approved_origins";
var SEPARATOR = ",";
var Cookies = require('cookies-js');
function _getApprovedOriginsValue() {
var result = Cookies.get(APPROVED_ORIGINS_KEY);
return result;
}
function _saveApprovedOrigins(originArray) {
var newOriginString = originArray.join(SEPARATOR);
console.log("Saving approved origins '" + newOriginString + "'");
// We could potentially make this a longer term cookie instead of just for the current session
var result = Cookies.set(APPROVED_ORIGINS_KEY, newOriginString);
return result;
}
// Adds an approved origins to the list already saved in a session cookie
function addApprovedOrigin(origin) {
if (origin) {
var origins = getApprovedOrigins();
origins.push(origin);
_saveApprovedOrigins(origins);
}
}
// Retrieves the origins which have already been approved by the user
function getApprovedOrigins() {
var originsString = _getApprovedOriginsValue();
if (!originsString || 0 === originsString.length) {
return [];
}
var origins = originsString.split(SEPARATOR);
return origins;
}
module.exports.addApprovedOrigin = addApprovedOrigin;
module.exports.getApprovedOrigins = getApprovedOrigins;