login.js 948 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // 邮箱登录
  2. const CryptoJS = require('crypto-js')
  3. const createOption = require('../util/option.js')
  4. module.exports = async (query, request) => {
  5. const data = {
  6. username: query.email,
  7. password: query.md5_password || CryptoJS.MD5(query.password).toString(),
  8. rememberLogin: 'true',
  9. }
  10. let result = await request(`/api/login`, data, {
  11. ...createOption(query),
  12. uaType: 'pc',
  13. })
  14. if (result.body.code === 502) {
  15. return {
  16. status: 200,
  17. body: {
  18. msg: '账号或密码错误',
  19. code: 502,
  20. message: '账号或密码错误',
  21. },
  22. }
  23. }
  24. if (result.body.code === 200) {
  25. result = {
  26. status: 200,
  27. body: {
  28. ...JSON.parse(
  29. JSON.stringify(result.body).replace(
  30. /avatarImgId_str/g,
  31. 'avatarImgIdStr',
  32. ),
  33. ),
  34. cookie: result.cookie.join(';'),
  35. },
  36. cookie: result.cookie,
  37. }
  38. }
  39. return result
  40. }