2015-10-30 16:57:03 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import requests from '../utils/requests';
|
2015-11-02 15:47:57 +01:00
|
|
|
import ApiUrls from '../constants/api_urls';
|
|
|
|
|
2015-10-30 16:57:03 +01:00
|
|
|
import UserActions from '../actions/user_actions';
|
|
|
|
|
|
|
|
|
|
|
|
const UserSource = {
|
2015-11-02 16:32:55 +01:00
|
|
|
lookupCurrentUser: {
|
2015-10-30 16:57:03 +01:00
|
|
|
remote() {
|
|
|
|
return requests.get('user');
|
|
|
|
},
|
|
|
|
|
|
|
|
local(state) {
|
2016-01-15 13:55:58 +01:00
|
|
|
return !Object.keys(state.currentUser).length ? state : {};
|
2015-10-30 16:57:03 +01:00
|
|
|
},
|
2016-01-15 13:55:58 +01:00
|
|
|
|
2015-11-02 16:32:55 +01:00
|
|
|
success: UserActions.successFetchCurrentUser,
|
2015-11-16 17:16:13 +01:00
|
|
|
error: UserActions.errorCurrentUser,
|
2016-01-15 13:55:58 +01:00
|
|
|
|
|
|
|
shouldFetch(state, invalidateCache) {
|
|
|
|
return invalidateCache || !Object.keys(state.currentUser).length;
|
2015-10-30 16:57:03 +01:00
|
|
|
}
|
2015-11-02 15:47:57 +01:00
|
|
|
},
|
|
|
|
|
2015-11-02 16:32:55 +01:00
|
|
|
performLogoutCurrentUser: {
|
2015-11-02 15:47:57 +01:00
|
|
|
remote() {
|
|
|
|
return requests.get(ApiUrls.users_logout);
|
|
|
|
},
|
2016-01-15 13:55:58 +01:00
|
|
|
|
2015-11-02 16:32:55 +01:00
|
|
|
success: UserActions.successLogoutCurrentUser,
|
2015-11-16 17:16:13 +01:00
|
|
|
error: UserActions.errorCurrentUser
|
2015-10-30 16:57:03 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-15 13:55:58 +01:00
|
|
|
export default UserSource;
|