login.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2018-2025, lengleng All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the pig4cloud.com developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: lengleng (wangiegie@gmail.com)
  16. */
  17. import request from '@/router/axios'
  18. export const loginByUsername = (username, password, code, randomStr) => {
  19. var grant_type = 'password'
  20. var scope = 'server'
  21. return request({
  22. url: '/auth/oauth/token',
  23. headers: {
  24. 'TENANT_ID': '1',
  25. 'Authorization': 'Basic cGlnOnBpZw=='
  26. },
  27. method: 'post',
  28. params: { username, password, randomStr, code, grant_type, scope }
  29. })
  30. }
  31. export const loginBySocial = (state, code) => {
  32. var grant_type = 'mobile'
  33. return request({
  34. url: '/auth/mobile/token',
  35. headers: {
  36. 'TENANT_ID': '1',
  37. 'Authorization': 'Basic cGlnOnBpZw=='
  38. },
  39. method: 'post',
  40. params: { mobile: state + '@' + code, grant_type }
  41. })
  42. }
  43. export const getUserInfo = () => {
  44. return request({
  45. url: '/admin/user/info',
  46. method: 'get'
  47. })
  48. }
  49. export const logout = () => {
  50. return request({
  51. url: '/auth/oauth/logout',
  52. method: 'delete'
  53. })
  54. }