2015-02-05 13:39:00 +01:00
|
|
|
var _username;
|
|
|
|
|
2016-04-24 22:41:37 +02:00
|
|
|
// Ref: http://stackoverflow.com/questions/10730362/get-cookie-by-name
|
2015-02-05 13:39:00 +01:00
|
|
|
function readCookie(name) {
|
|
|
|
var nameEQ = name + "=";
|
|
|
|
var ca = document.cookie.split(';');
|
2016-04-24 22:41:37 +02:00
|
|
|
for (var i=0;i < ca.length;i++) {
|
2015-02-05 13:39:00 +01:00
|
|
|
var c = ca[i];
|
|
|
|
while (c.charAt(0)==' ') {
|
2016-04-24 22:41:37 +02:00
|
|
|
c = c.substring(1, c.length);
|
2015-02-05 13:39:00 +01:00
|
|
|
}
|
|
|
|
if (c.indexOf(nameEQ) === 0) {
|
2016-04-24 22:41:37 +02:00
|
|
|
return c.substring(nameEQ.length, c.length);
|
2015-02-05 13:39:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var UserStore = {
|
|
|
|
init: function init() {
|
2016-04-24 22:41:37 +02:00
|
|
|
_username = readCookie("username");
|
2015-02-05 13:39:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function set(username) {
|
2016-04-24 22:41:37 +02:00
|
|
|
_username=username;
|
|
|
|
document.cookie="username="+_username+"; expires=Thu, 18 Dec 2099 12:00:00 UTC";
|
2015-02-05 13:39:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
get: function get() {
|
2016-04-24 22:41:37 +02:00
|
|
|
return _username;
|
2015-02-05 13:39:00 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = UserStore;
|