user.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { param2Obj } from './utils'
  2. const tokens = {
  3. admin: {
  4. token: 'admin-token'
  5. },
  6. editor: {
  7. token: 'editor-token'
  8. }
  9. }
  10. const users = {
  11. 'admin-token': {
  12. roles: ['admin'],
  13. introduction: 'I am a super administrator',
  14. avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
  15. name: 'Super Admin'
  16. },
  17. 'editor-token': {
  18. roles: ['editor'],
  19. introduction: 'I am an editor',
  20. avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
  21. name: 'Normal Editor'
  22. }
  23. }
  24. export default {
  25. login: res => {
  26. const { username } = JSON.parse(res.body)
  27. const data = tokens[username]
  28. if (data) {
  29. return {
  30. code: 20000,
  31. data
  32. }
  33. }
  34. return {
  35. code: 60204,
  36. message: 'Account and password are incorrect.'
  37. }
  38. },
  39. getInfo: res => {
  40. const { token } = param2Obj(res.url)
  41. const info = users[token]
  42. if (info) {
  43. return {
  44. code: 20000,
  45. data: info
  46. }
  47. }
  48. return {
  49. code: 50008,
  50. message: 'Login failed, unable to get user details.'
  51. }
  52. },
  53. logout: () => {
  54. return {
  55. code: 20000,
  56. data: 'success'
  57. }
  58. }
  59. }