user.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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: "/socialLogin",
  43. type: "post",
  44. response(config) {
  45. const { code } = config.body;
  46. if (!code) {
  47. return {
  48. code: 500,
  49. msg: "未成功获取Token。",
  50. };
  51. }
  52. return {
  53. code: 200,
  54. msg: "success",
  55. data: { accessToken: accessTokens["admin"] },
  56. };
  57. },
  58. },
  59. {
  60. url: "/register",
  61. type: "post",
  62. response() {
  63. return {
  64. code: 200,
  65. msg: "模拟注册成功",
  66. };
  67. },
  68. },
  69. {
  70. url: "/userInfo",
  71. type: "post",
  72. response(config) {
  73. const { accessToken } = config.body;
  74. let roles = ["admin"];
  75. let ability = ["READ"];
  76. let username = "admin";
  77. if ("admin-accessToken" === accessToken) {
  78. roles = ["admin"];
  79. ability = ["READ", "WRITE", "DELETE"];
  80. username = "admin";
  81. }
  82. if ("editor-accessToken" === accessToken) {
  83. roles = ["editor"];
  84. ability = ["READ", "WRITE"];
  85. username = "editor";
  86. }
  87. if ("test-accessToken" === accessToken) {
  88. roles = ["admin", "editor"];
  89. ability = ["READ"];
  90. username = "test";
  91. }
  92. return {
  93. code: 200,
  94. msg: "success",
  95. data: {
  96. roles,
  97. ability,
  98. username,
  99. "avatar|1": [
  100. "https://i.gtimg.cn/club/item/face/img/2/15922_100.gif",
  101. "https://i.gtimg.cn/club/item/face/img/8/15918_100.gif",
  102. ],
  103. },
  104. };
  105. },
  106. },
  107. {
  108. url: "/logout",
  109. type: "post",
  110. response() {
  111. return {
  112. code: 200,
  113. msg: "success",
  114. };
  115. },
  116. },
  117. ];