1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/packages/unleash-frontend/public/js/stores/UserStore.js

36 lines
819 B
JavaScript
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
let _username;
// Ref: http://stackoverflow.com/questions/10730362/get-cookie-by-name
function readCookie(name) {
2016-06-18 21:53:18 +02:00
const nameEQ = `${name}=`;
const ca = document.cookie.split(';');
for (let i=0;i < ca.length;i++) {
let c = ca[i];
2016-06-18 22:23:19 +02:00
while (c.charAt(0)==' ') { // eslint-disable-line eqeqeq
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) === 0) {
return c.substring(nameEQ.length, c.length);
}
}
return null;
}
2016-06-18 21:53:18 +02:00
const UserStore = {
init() {
2016-06-18 21:55:46 +02:00
_username = readCookie('username');
},
2016-06-18 21:53:18 +02:00
set(username) {
_username=username;
2016-06-18 21:53:18 +02:00
document.cookie=`username=${_username}; expires=Thu, 18 Dec 2099 12:00:00 UTC`;
},
2016-06-18 21:53:18 +02:00
get() {
return _username;
2016-06-18 21:55:46 +02:00
},
};
module.exports = UserStore;