diff --git a/client/src/lib-app/local-store.js b/client/src/lib-app/local-store.js new file mode 100644 index 00000000..172aa696 --- /dev/null +++ b/client/src/lib-app/local-store.js @@ -0,0 +1,39 @@ +import LocalStorage from 'localstorage'; + +class LocalStore { + + constructor() { + this.setItem = LocalStorage.setItem; + this.getItem = LocalStorage.getItem; + } + + initialize() { + if (this.isRememberDataExpired()) { + this.clearRememberData(); + } + + if (!this.getItem('language')) { + this.setItem('language', 'english'); + } + } + + storeRememberData({token, userId, expiration}) { + this.setItem('rememberData', { + token, + userId, + expiration + }); + } + + isRememberDataExpired() { + let rememberData = this.getItem('rememberData'); + + return rememberData && rememberData.expirationDate > 2016 + } + + clearRememberData() { + this.setItem('rememberData', null); + } +} + +export default new LocalStore(); \ No newline at end of file diff --git a/client/src/lib-app/session-store.js b/client/src/lib-app/session-store.js index f6a05b77..a2397226 100644 --- a/client/src/lib-app/session-store.js +++ b/client/src/lib-app/session-store.js @@ -1,11 +1,9 @@ import SessionStorage from 'sessionstorage'; - +import LocalStore from 'lib-app/local-store'; class SessionStore { static initialize() { - if (!SessionStorage.getItem('language')) { - SessionStorage.setItem('language', 'english'); - } + } static createSession(userId, token) { diff --git a/client/src/stores/user-store.js b/client/src/stores/user-store.js index 93118c36..dc40df3c 100644 --- a/client/src/stores/user-store.js +++ b/client/src/stores/user-store.js @@ -29,8 +29,8 @@ const UserStore = Reflux.createStore({ path: 'user/logout', onSuccess: function () { SessionStore.closeSession(); - this.trigger('LOGOUT'); CommonActions.loggedOut(); + this.trigger('LOGOUT'); }.bind(this) }); }, @@ -41,8 +41,8 @@ const UserStore = Reflux.createStore({ handleLoginSuccess(result) { SessionStore.createSession(result.data.userId, result.data.token); - this.trigger('LOGIN_SUCCESS'); CommonActions.logged(); + this.trigger('LOGIN_SUCCESS'); }, handleLoginFail() {