You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

95 lines
2.5 KiB

  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. import qs from 'qs'
  19. const scope = 'server'
  20. export const loginByUsername = (username, password, code, randomStr) => {
  21. let grant_type = 'password'
  22. let dataObj = qs.stringify({'username': username, 'password': password})
  23. return request({
  24. url: '/auth/oauth/token',
  25. headers: {
  26. isToken: false,
  27. 'TENANT-ID': '1',
  28. 'Authorization': 'Basic cGlnOnBpZw=='
  29. },
  30. method: 'post',
  31. params: {randomStr, code, grant_type},
  32. data: dataObj
  33. })
  34. }
  35. export const refreshToken = (refresh_token) => {
  36. const grant_type = 'refresh_token'
  37. return request({
  38. url: '/auth/oauth/token',
  39. headers: {
  40. 'isToken': false,
  41. 'TENANT-ID': '1',
  42. 'Authorization': 'Basic cGlnOnBpZw=='
  43. },
  44. method: 'post',
  45. params: {refresh_token, grant_type, scope}
  46. })
  47. }
  48. export const loginByMobile = (mobile, code) => {
  49. const grant_type = 'mobile'
  50. return request({
  51. url: '/auth/mobile/token/sms',
  52. headers: {
  53. isToken: false,
  54. 'TENANT-ID': '1',
  55. 'Authorization': 'Basic cGlnOnBpZw=='
  56. },
  57. method: 'post',
  58. params: {mobile: 'SMS@' + mobile, code: code, grant_type}
  59. })
  60. }
  61. export const loginBySocial = (state, code) => {
  62. const grant_type = 'mobile'
  63. return request({
  64. url: '/auth/mobile/token/social',
  65. headers: {
  66. isToken: false,
  67. 'TENANT-ID': '1',
  68. 'Authorization': 'Basic cGlnOnBpZw=='
  69. },
  70. method: 'post',
  71. params: {mobile: state + '@' + code, grant_type}
  72. })
  73. }
  74. export const getUserInfo = (query) => {
  75. return request({
  76. url: '/admin/user/info',
  77. method: 'get',
  78. params:query
  79. })
  80. }
  81. export const logout = () => {
  82. return request({
  83. url: '/auth/token/logout',
  84. method: 'delete'
  85. })
  86. }