2019-02-20 13:16:24 +08:00
|
|
|
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-19 20:41:52 +08:00
|
|
|
export default [
|
|
|
|
// user login
|
|
|
|
{
|
|
|
|
url: '/user/login',
|
|
|
|
type: 'post',
|
|
|
|
response: config => {
|
|
|
|
const { username } = config.body
|
|
|
|
const token = tokens[username]
|
|
|
|
|
|
|
|
// mock error
|
|
|
|
if (!token) {
|
|
|
|
return {
|
|
|
|
code: 60204,
|
|
|
|
message: 'Account and password are incorrect.'
|
|
|
|
}
|
|
|
|
}
|
2019-02-20 13:16:24 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
code: 20000,
|
2019-04-19 20:41:52 +08:00
|
|
|
data: token
|
2019-02-20 13:16:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-04-19 20:41:52 +08:00
|
|
|
// get user info
|
|
|
|
{
|
|
|
|
url: '/user/info\.*',
|
|
|
|
type: 'get',
|
|
|
|
response: config => {
|
|
|
|
const { token } = config.query
|
|
|
|
const info = users[token]
|
|
|
|
|
|
|
|
// mock error
|
|
|
|
if (!info) {
|
|
|
|
return {
|
|
|
|
code: 50008,
|
|
|
|
message: 'Login failed, unable to get user details.'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-20 13:16:24 +08:00
|
|
|
return {
|
|
|
|
code: 20000,
|
|
|
|
data: info
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-04-19 20:41:52 +08:00
|
|
|
|
|
|
|
// user logout
|
|
|
|
{
|
|
|
|
url: '/user/logout',
|
|
|
|
type: 'post',
|
|
|
|
response: _ => {
|
|
|
|
return {
|
|
|
|
code: 20000,
|
|
|
|
data: 'success'
|
|
|
|
}
|
2019-02-20 13:16:24 +08:00
|
|
|
}
|
|
|
|
}
|
2019-04-19 20:41:52 +08:00
|
|
|
]
|