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
74 lines (69 loc) · 1.56 KB
/
user.js
File metadata and controls
74 lines (69 loc) · 1.56 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
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 storageService from '../services/storage'
export const checkToken = createAction(types.CHECK_TOKEN, async(token) => {
const userLoginInfo = await userService.checkToken(token)
const user = await userService
.getUserInfo(userLoginInfo.loginname)
.then((data) => {
return {
secret: userLoginInfo,
publicInfo: data
}
})
tokenService.setToken(token)
return user
}, (token, resolved) => {
return {
resolved: resolved,
sync: 'user'
}
})
export const updateClientUserInfo = createAction(types.UPDATE_CLIENT_USER_INFO, async(user) => {
return await userService.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.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 () {
try {
storageService.removeItem('topic')
storageService.removeItem('message')
} catch (err) {
console.warn(err)
}
return {
type: types.CLEAR
}
}