2016-06-18 21:53:18 +02:00
|
|
|
'use strict';
|
|
|
|
let _username;
|
2015-02-05 13:39:00 +01:00
|
|
|
|
2016-04-24 22:41:37 +02:00
|
|
|
// Ref: http://stackoverflow.com/questions/10730362/get-cookie-by-name
|
2016-08-22 15:12:05 +02:00
|
|
|
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
|
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;
|
|
|
|
}
|
|
|
|
|
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');
|
2015-02-05 13:39:00 +01:00
|
|
|
},
|
|
|
|
|
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`;
|
2015-02-05 13:39:00 +01:00
|
|
|
},
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
get () {
|
2016-04-24 22:41:37 +02:00
|
|
|
return _username;
|
2016-06-18 21:55:46 +02:00
|
|
|
},
|
2015-02-05 13:39:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = UserStore;
|