Ivan - Add local storage class [skip ci]

This commit is contained in:
Ivan Diaz 2016-07-19 10:45:35 -03:00
parent bc66d74f73
commit 0e6a73f4eb
3 changed files with 43 additions and 6 deletions

View File

@ -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();

View File

@ -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) {

View File

@ -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() {