login.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. 'TENANT-ID': '1',
  54. 'Authorization': 'Basic cGlnOnBpZw=='
  55. },
  56. method: 'post',
  57. params: {mobile: 'SMS@' + mobile, code: code, grant_type}
  58. })
  59. }
  60. export const loginBySocial = (state, code) => {
  61. const grant_type = 'mobile'
  62. return request({
  63. url: '/auth/mobile/token/social',
  64. headers: {
  65. 'TENANT-ID': '1',
  66. 'Authorization': 'Basic cGlnOnBpZw=='
  67. },
  68. method: 'post',
  69. params: {mobile: state + '@' + code, grant_type}
  70. })
  71. }
  72. export const logout = () => {
  73. return request({
  74. url: '/auth/token/logout',
  75. method: 'delete'
  76. })
  77. }