user.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. let { token } = config.query
  50. token = 'admin-token'
  51. const info = users[token]
  52. // mock error
  53. if (!info) {
  54. return {
  55. code: 50008,
  56. message: 'Login failed, unable to get user details.'
  57. }
  58. }
  59. return {
  60. code: 200,
  61. data: info
  62. }
  63. }
  64. },
  65. // user logout
  66. {
  67. url: '/authdata/logout',
  68. type: 'post',
  69. response: _ => {
  70. return {
  71. code: 200,
  72. data: 'success'
  73. }
  74. }
  75. }
  76. ]