join_admin/mock/user.js

88 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-12-03 18:03:25 +00:00
const tokens = {
admin: {
token: 'admin-token'
},
editor: {
token: 'editor-token'
2019-12-03 22:03:26 +00:00
},
user: {
token: 'editor-token'
2019-12-03 18:03:25 +00:00
}
}
const users = {
'admin-token': {
roles: ['admin'],
2019-12-03 22:03:26 +00:00
introduction: 'Projektmanager bei RedBull',
2019-12-03 18:03:25 +00:00
avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
2019-12-03 22:03:26 +00:00
name: 'Julia Krammer'
2019-12-03 18:03:25 +00:00
},
'editor-token': {
roles: ['editor'],
introduction: 'Backend Developer bei RedBull',
avatar: 'https://lbsfilm.at/media/pages/about/1056669128-1567191147/square-small.jpg',
name: 'Lukas Bachschwell'
}
}
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.'
}
}
return {
code: 20000,
data: token
}
}
},
// 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.'
}
}
return {
code: 20000,
data: info
}
}
},
// user logout
{
url: '/user/logout',
type: 'post',
response: _ => {
return {
code: 20000,
data: 'success'
}
}
}
]