forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.js
More file actions
87 lines (77 loc) · 1.83 KB
/
user.js
File metadata and controls
87 lines (77 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {createAction} from 'redux-actions';
import * as types from '../constants/ActionTypes';
import * as userService from '../services/userService';
import * as tokenService from '../services/token';
import * as topicService from '../services/topicService';
import * as messageService from '../services/messageService';
export const checkToken = createAction(types.CHECK_TOKEN, async(token)=> {
const userLoginInfo = await userService.req.checkToken(token);
const user = await userService.req
.getUserInfo(userLoginInfo.loginname)
.then((data)=> {
return {
secret: userLoginInfo,
publicInfo: data
};
});
tokenService.setToken(token);
return user;
}, (token, resolved)=> {
return {
resolved: resolved,
sync: 'user'
}
});
export const getUserFromStorage = createAction(types.GET_USER_FROM_STORAGE, async()=> {
return await userService.storage.getUser()
.then(user=> {
tokenService.setToken(user.secret.token);
return user;
});
}, (resolved)=> {
return {
resolved
}
});
export const updateClientUserInfo = createAction(types.UPDATE_CLIENT_USER_INFO, async(user)=> {
return await userService.req.getUserInfo(user.secret.loginname)
.then(userInfo=> {
if (userInfo) {
return userInfo;
}
throw 'getUserInfoError'
});
}, ()=> {
return {
sync: 'user'
}
});
export const getUserInfo = createAction(types.GET_USER_INFO, async(loginName)=> {
return await userService.req.getUserInfo(loginName)
.then(userInfo=> {
if (userInfo) {
return userInfo;
}
throw 'getUserInfoError'
});
}, (userName)=> {
return {
userName,
sync: 'user'
}
});
export const logout = function () {
return {
type: types.LOGOUT,
meta: {
sync: 'user'
}
}
};
export const clear = function () {
topicService.storage.removeAllTopics();
messageService.storage.clear();
return {
type: types.CLEAR
}
};