1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/packages/unleash-frontend/public/js/stores/UserStore.js

36 lines
843 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 (cookieName) {
const nameEQ = `${cookieName}=`;
2016-06-18 21:53:18 +02:00
const ca = document.cookie.split(';');
2016-07-02 11:54:50 +02:00
for (let i = 0;i < ca.length;i++) {
2016-06-18 21:53:18 +02:00
let c = ca[i];
2016-07-02 11:54:50 +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 = {
2016-07-02 11:54:50 +02:00
init () {
2016-06-18 21:55:46 +02:00
_username = readCookie('username');
},
2016-07-02 11:54:50 +02:00
set (username) {
_username = username;
document.cookie = `username=${_username}; expires=Thu, 18 Dec 2099 12:00:00 UTC`;
},
2016-07-02 11:54:50 +02:00
get () {
return _username;
2016-06-18 21:55:46 +02:00
},
};
module.exports = UserStore;