login.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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( newPassword,confirmPassword ) {
  56. return request({
  57. url: '/system/user/profile/reset-password',
  58. method: 'put',
  59. data: {
  60. newPassword,
  61. confirmPassword
  62. }
  63. })
  64. }
  65. // 获取登录验证码
  66. export function sendSmsCode(mobile, scene) {
  67. return request({
  68. url: '/system/auth/send-sms-code',
  69. method: 'post',
  70. data: {
  71. mobile,
  72. scene
  73. }
  74. })
  75. }
  76. // 短信验证码重置密码
  77. export function smsResetPassword(mobile, code) {
  78. return request({
  79. url: '/system/auth/sms-reset-password',
  80. method: 'post',
  81. data: {
  82. mobile,
  83. code
  84. }
  85. })
  86. }
  87. // 短信验证码注册
  88. export function smsRegister(mobile, code) {
  89. return request({
  90. url: '/system/auth/sms-register',
  91. method: 'post',
  92. data: {
  93. mobile,
  94. code
  95. }
  96. })
  97. }
  98. // 短信验证码登录
  99. export function smsLogin(mobile, code) {
  100. return request({
  101. url: '/system/auth/sms-login',
  102. method: 'post',
  103. data: {
  104. mobile,
  105. code
  106. }
  107. })
  108. }
  109. // 刷新访问令牌
  110. export function refreshToken() {
  111. return service({
  112. url: '/system/auth/refresh-token?refreshToken=' + getRefreshToken(),
  113. method: 'post'
  114. })
  115. }
  116. // ========== OAUTH 2.0 相关 ==========
  117. export function getAuthorize(clientId) {
  118. return request({
  119. url: '/system/oauth2/authorize?clientId=' + clientId,
  120. method: 'get'
  121. })
  122. }
  123. export function authorize(responseType, clientId, redirectUri, state,
  124. autoApprove, checkedScopes, uncheckedScopes) {
  125. // 构建 scopes
  126. const scopes = {}
  127. for (const scope of checkedScopes) {
  128. scopes[scope] = true
  129. }
  130. for (const scope of uncheckedScopes) {
  131. scopes[scope] = false
  132. }
  133. // 发起请求
  134. return service({
  135. url: '/system/oauth2/authorize',
  136. headers: {
  137. 'Content-type': 'application/x-www-form-urlencoded'
  138. },
  139. params: {
  140. response_type: responseType,
  141. client_id: clientId,
  142. redirect_uri: redirectUri,
  143. state: state,
  144. auto_approve: autoApprove,
  145. scope: JSON.stringify(scopes)
  146. },
  147. method: 'post'
  148. })
  149. }
  150. // 获取验证图片 以及token
  151. export function reqGet(data) {
  152. return request({
  153. url: 'system/captcha/get',
  154. method: 'post',
  155. data
  156. })
  157. }
  158. // 滑动或者点选验证
  159. export function reqCheck(data) {
  160. return request({
  161. url: '/system/captcha/check',
  162. method: 'post',
  163. data
  164. })
  165. }
  166. export class socialBindLogin {
  167. }