user.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const tokens = {
  2. admin: {
  3. token: 'admin-token'
  4. },
  5. editor: {
  6. token: 'editor-token'
  7. }
  8. }
  9. const users = {
  10. 'admin-token': {
  11. role: ['admin'],
  12. introduction: 'I am a super administrator',
  13. avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
  14. name: 'Super Admin'
  15. },
  16. 'editor-token': {
  17. role: ['editor'],
  18. introduction: 'I am an editor',
  19. avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
  20. name: 'Normal Editor'
  21. }
  22. }
  23. export default [
  24. // user login
  25. {
  26. url: '/auth',
  27. type: 'post',
  28. response: config => {
  29. const { username } = config.body
  30. const token = tokens[username]
  31. // mock error
  32. if (!token) {
  33. return {
  34. code: 60204,
  35. message: 'Account and password are incorrect.'
  36. }
  37. }
  38. return {
  39. code: 200,
  40. data: token
  41. }
  42. }
  43. },
  44. // get user info
  45. {
  46. url: '/authdata/userinfo\.*',
  47. type: 'get',
  48. response: config => {
  49. console.log(config)
  50. let { token } = config.query
  51. token = 'admin-token'
  52. const info = users[token]
  53. // mock error
  54. if (!info) {
  55. return {
  56. code: 50008,
  57. message: 'Login failed, unable to get user details.'
  58. }
  59. }
  60. return {
  61. code: 200,
  62. data: info
  63. }
  64. }
  65. },
  66. // user logout
  67. {
  68. url: '/authdata/logout',
  69. type: 'post',
  70. response: _ => {
  71. return {
  72. code: 200,
  73. data: 'success'
  74. }
  75. }
  76. }
  77. ]