user.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const accessTokens = {
  2. admin: 'admin-accessToken',
  3. editor: 'editor-accessToken',
  4. test: 'test-accessToken',
  5. }
  6. module.exports = [
  7. {
  8. url: '/publicKey',
  9. type: 'post',
  10. response() {
  11. return {
  12. code: 200,
  13. msg: 'success',
  14. data: {
  15. mockServer: true,
  16. publicKey:
  17. 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBT2vr+dhZElF73FJ6xiP181txKWUSNLPQQlid6DUJhGAOZblluafIdLmnUyKE8mMHhT3R+Ib3ssZcJku6Hn72yHYj/qPkCGFv0eFo7G+GJfDIUeDyalBN0QsuiE/XzPHJBuJDfRArOiWvH0BXOv5kpeXSXM8yTt5Na1jAYSiQ/wIDAQAB',
  18. },
  19. }
  20. },
  21. },
  22. {
  23. url: '/login',
  24. type: 'post',
  25. response(config) {
  26. const { username } = config.body
  27. const accessToken = accessTokens[username]
  28. if (!accessToken) {
  29. return {
  30. code: 500,
  31. msg: '帐户或密码不正确。',
  32. }
  33. }
  34. return {
  35. code: 200,
  36. msg: 'success',
  37. data: { accessToken },
  38. }
  39. },
  40. },
  41. {
  42. url: '/register',
  43. type: 'post',
  44. response() {
  45. return {
  46. code: 200,
  47. msg: '模拟注册成功',
  48. }
  49. },
  50. },
  51. {
  52. url: '/userInfo',
  53. type: 'post',
  54. response(config) {
  55. const { accessToken } = config.body
  56. let permissions = ['admin']
  57. let username = 'admin'
  58. if ('admin-accessToken' === accessToken) {
  59. permissions = ['admin']
  60. username = 'admin'
  61. }
  62. if ('editor-accessToken' === accessToken) {
  63. permissions = ['editor']
  64. username = 'editor'
  65. }
  66. if ('test-accessToken' === accessToken) {
  67. permissions = ['admin', 'editor']
  68. username = 'test'
  69. }
  70. return {
  71. code: 200,
  72. msg: 'success',
  73. data: {
  74. permissions,
  75. username,
  76. 'avatar|1': [
  77. 'https://i.gtimg.cn/club/item/face/img/2/15922_100.gif',
  78. 'https://i.gtimg.cn/club/item/face/img/8/15918_100.gif',
  79. ],
  80. },
  81. }
  82. },
  83. },
  84. {
  85. url: '/logout',
  86. type: 'post',
  87. response() {
  88. return {
  89. code: 200,
  90. msg: 'success',
  91. }
  92. },
  93. },
  94. ]