user.js
1.2 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
import {
param2Obj
} from './utils'
const tokens = {
admin: {
token: 'admin-token'
},
editor: {
token: 'editor-token'
}
}
const users = {
'admin-token': {
roles: ['admin'],
introduction: 'I am a super administrator',
avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
name: 'Super Admin'
},
'editor-token': {
roles: ['editor'],
introduction: 'I am an editor',
avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
name: 'Normal Editor'
}
}
export default {
login: res => {
const {
username
} = JSON.parse(res.body)
const data = tokens[username]
if (data) {
return {
code: 200,
content: data
}
}
return {
code: 60204,
message: 'Account and password are incorrect.'
}
},
getInfo: res => {
const {
token
} = param2Obj(res.url)
const info = users[token]
if (info) {
return {
code: 200,
content: info
}
}
return {
code: 50008,
message: 'Login failed, unable to get user details.'
}
},
logout: () => {
return {
code: 200,
data: 'success'
}
}
}