user.js 1.9 KB

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