login.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import request from '@/utils/request'
  2. import { getRefreshToken } from '@/utils/auth'
  3. import service from '@/utils/request'
  4. // 登录方法
  5. export function login(username, password, captchaVerification, socialType, socialCode, socialState) {
  6. const data = {
  7. username,
  8. password,
  9. captchaVerification,
  10. // 社交相关
  11. socialType,
  12. socialCode,
  13. socialState
  14. }
  15. return request({
  16. url: '/system/auth/login',
  17. method: 'post',
  18. data: data
  19. })
  20. }
  21. // 获取用户详细信息
  22. export function getInfo() {
  23. return request({
  24. url: '/system/auth/get-permission-info',
  25. method: 'get'
  26. })
  27. }
  28. // 退出方法
  29. export function logout() {
  30. return request({
  31. url: '/system/auth/logout',
  32. method: 'post'
  33. })
  34. }
  35. // 社交授权的跳转
  36. export function socialAuthRedirect(type, redirectUri) {
  37. return request({
  38. url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri,
  39. method: 'get'
  40. })
  41. }
  42. // 社交快捷登录,使用 code 授权码
  43. export function socialLogin(type, code, state) {
  44. return request({
  45. url: '/system/auth/social-login',
  46. method: 'post',
  47. data: {
  48. type,
  49. code,
  50. state
  51. }
  52. })
  53. }
  54. // 修改密码
  55. export function updatePassword( password ) {
  56. return request({
  57. url: '/system/user/profile/update-password',
  58. method: 'post',
  59. data: {
  60. password,
  61. }
  62. })
  63. }
  64. // 获取登录验证码
  65. export function sendSmsCode(mobile, scene) {
  66. return request({
  67. url: '/system/auth/send-sms-code',
  68. method: 'post',
  69. data: {
  70. mobile,
  71. scene
  72. }
  73. })
  74. }
  75. // 短信验证码注册
  76. export function smsRegister(mobile, code) {
  77. return request({
  78. url: '/system/auth/sms-register',
  79. method: 'post',
  80. data: {
  81. mobile,
  82. code
  83. }
  84. })
  85. }
  86. // 短信验证码登录
  87. export function smsLogin(mobile, code) {
  88. return request({
  89. url: '/system/auth/sms-login',
  90. method: 'post',
  91. data: {
  92. mobile,
  93. code
  94. }
  95. })
  96. }
  97. // 刷新访问令牌
  98. export function refreshToken() {
  99. return service({
  100. url: '/system/auth/refresh-token?refreshToken=' + getRefreshToken(),
  101. method: 'post'
  102. })
  103. }
  104. // ========== OAUTH 2.0 相关 ==========
  105. export function getAuthorize(clientId) {
  106. return request({
  107. url: '/system/oauth2/authorize?clientId=' + clientId,
  108. method: 'get'
  109. })
  110. }
  111. export function authorize(responseType, clientId, redirectUri, state,
  112. autoApprove, checkedScopes, uncheckedScopes) {
  113. // 构建 scopes
  114. const scopes = {}
  115. for (const scope of checkedScopes) {
  116. scopes[scope] = true
  117. }
  118. for (const scope of uncheckedScopes) {
  119. scopes[scope] = false
  120. }
  121. // 发起请求
  122. return service({
  123. url: '/system/oauth2/authorize',
  124. headers: {
  125. 'Content-type': 'application/x-www-form-urlencoded'
  126. },
  127. params: {
  128. response_type: responseType,
  129. client_id: clientId,
  130. redirect_uri: redirectUri,
  131. state: state,
  132. auto_approve: autoApprove,
  133. scope: JSON.stringify(scopes)
  134. },
  135. method: 'post'
  136. })
  137. }
  138. // 获取验证图片 以及token
  139. export function reqGet(data) {
  140. return request({
  141. url: 'system/captcha/get',
  142. method: 'post',
  143. data
  144. })
  145. }
  146. // 滑动或者点选验证
  147. export function reqCheck(data) {
  148. return request({
  149. url: '/system/captcha/check',
  150. method: 'post',
  151. data
  152. })
  153. }
  154. export class socialBindLogin {
  155. }