2015-10-30 16:57:03 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import UserActions from '../actions/user_actions';
|
|
|
|
|
2016-06-14 16:53:18 +02:00
|
|
|
import request from '../utils/request';
|
2016-06-14 13:05:57 +02:00
|
|
|
|
2015-10-30 16:57:03 +01:00
|
|
|
|
|
|
|
const UserSource = {
|
2015-11-02 16:32:55 +01:00
|
|
|
lookupCurrentUser: {
|
2015-10-30 16:57:03 +01:00
|
|
|
remote() {
|
2016-06-14 16:53:18 +02:00
|
|
|
return request('user');
|
2015-10-30 16:57:03 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
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() {
|
2016-06-14 16:53:18 +02:00
|
|
|
return request('users_logout');
|
2015-11-02 15:47:57 +01:00
|
|
|
},
|
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;
|