reghao 2 anos atrás
pai
commit
ddb6c7ac40

+ 55 - 0
src/api/account.js

@@ -61,3 +61,58 @@ export function login(loginData) {
 export function logout() {
   return get(accountApi.logoutApi)
 }
+
+
+// 登录服务接口
+export const ServePubkey = () => {
+  return get('/api/account/code/pubkey')
+}
+
+// 登录服务接口
+export const ServeLogin = data => {
+  return post('/api/account/auth/signin', data)
+}
+
+// 登录注销
+export const ServeLogout = () => {
+  return post('/api/account/auth/signout')
+}
+
+// 注册服务接口
+export const ServeRegister = data => {
+  return post('/api/account/registry/create', data)
+}
+
+// 发送找回密码验证码
+export const ServeSendVerifyCode = data => {
+  return post('/api/account/code/verify', data)
+}
+
+// 发送邮箱验证码服务接口
+export const ServeRegistryCheck = data => {
+  return post('/api/account/registry/check', data)
+}
+
+export const ServeCaptcha = () => {
+  return get('/api/account/code/captcha')
+}
+
+// 刷新登录Token服务接口
+export const ServeRefreshToken = (data) => {
+  return post('/api/account/token/refresh', data)
+}
+
+// 重置密码服务
+export const ServeForgetPassword = data => {
+  return post('/api/account/password/reset', data)
+}
+
+// 获取登录记录
+export const ServeLoginRecord = () => {
+  return get('/api/account/login/record')
+}
+
+// 注销某次登录
+export const ServeLoginDeactive = (loginId) => {
+  return post('/api/account/login/deactive/' + loginId)
+}

+ 0 - 56
src/api/auth.js

@@ -1,56 +0,0 @@
-// 授权相关接口
-import { get, post } from '@/utils/request'
-
-// 登录服务接口
-export const ServePubkey = () => {
-  return get('/api/account/code/pubkey')
-}
-
-// 登录服务接口
-export const ServeLogin = data => {
-  return post('/api/account/auth/signin', data)
-}
-
-// 登录注销
-export const ServeLogout = () => {
-  return post('/api/account/auth/signout')
-}
-
-// 注册服务接口
-export const ServeRegister = data => {
-  return post('/api/account/registry/create', data)
-}
-
-// 发送找回密码验证码
-export const ServeSendVerifyCode = data => {
-  return post('/api/account/code/verify', data)
-}
-
-// 发送邮箱验证码服务接口
-export const ServeRegistryCheck = data => {
-  return post('/api/account/registry/check', data)
-}
-
-export const ServeCaptcha = () => {
-  return get('/api/account/code/captcha')
-}
-
-// 刷新登录Token服务接口
-export const ServeRefreshToken = (data) => {
-  return post('/api/account/token/refresh', data)
-}
-
-// 重置密码服务
-export const ServeForgetPassword = data => {
-  return post('/api/account/password/reset', data)
-}
-
-// 获取登录记录
-export const ServeLoginRecord = () => {
-  return get('/api/account/login/record')
-}
-
-// 注销某次登录
-export const ServeLoginDeactive = (loginId) => {
-  return post('/api/account/login/deactive/' + loginId)
-}

+ 3 - 43
src/utils/request.js

@@ -22,55 +22,15 @@ const loading = null
 
 // 请求拦截器
 instance.interceptors.request.use(config => {
-  const token = store.getters.token
-  if (token) {
+  const token1 = store.getters.token
+  if (token1) {
     // 在请求的 Authorization 首部添加 token
     config.headers.Authorization = 'Bearer ' + token
   }
   return config
 }, error => {
   return Promise.reject(error)
-}
-)
-
-/*instance.interceptors.request.use(config => {
-  const token = Vue.$cookies.get('token')
-  if (token === null) {
-    console.log('no cookie exist')
-  } else {
-    console.log('token in cookie: ' + token)
-  }
-
-  const accessToken = getAccessToken()
-  const refreshToken = getRefreshToken()
-  if (accessToken) {
-    config.headers['Authorization'] = `Bearer ${accessToken}`
-  } else if (refreshToken) {
-    fetch(`//account.reghao.cn/api/account/token/refresh`, {
-      headers: {
-        'Content-Type': 'application/json; charset=UTF-8'
-      },
-      method: 'POST',
-      credentials: 'include',
-      body: JSON.stringify({
-        refreshToken: refreshToken
-      })
-    }).then(response => response.json()).then(res => {
-      if (res.code === 0) {
-        setUserToken(res.data)
-        config.headers['Authorization'] = `Bearer ${res.data.accessToken}`
-      } else {
-        // removeAll()
-      }
-    }).catch(e => {
-      console.log(e)
-    }).finally(() => {
-    })
-  }
-  return config
-}, error => {
-  return Promise.reject(error)
-})*/
+})
 
 // 响应拦截器
 instance.interceptors.response.use(

+ 1 - 1
src/views/sso/forget.vue

@@ -86,7 +86,7 @@
 </template>
 
 <script>
-import { ServeForgetPassword, ServeSendVerifyCode } from '@/api/auth'
+import { ServeForgetPassword, ServeSendVerifyCode } from '@/api/account'
 import { isMobile } from '@/utils/validate'
 import SmsLock from '@/utils/sms-lock'
 

+ 3 - 2
src/views/sso/login.vue

@@ -81,7 +81,7 @@
 </template>
 
 <script>
-import {ServeCaptcha, ServeLogin, ServePubkey, ServeSendVerifyCode} from '@/api/auth'
+import {ServeCaptcha, ServeLogin, ServePubkey, ServeSendVerifyCode} from '@/api/account'
 import { setUserToken, getUserInfo } from '@/utils/auth'
 import { userMixin } from 'assets/js/mixin'
 import { isMobile } from '@/utils/validate'
@@ -146,7 +146,6 @@ export default {
     if (token !== null) {
       this.$router.push('/')
     } else {
-      this.getCaptcha()
       this.getPubkey()
       this.smsLockObj = new SmsLock('LOGIN_SMS', 60)
     }
@@ -182,6 +181,8 @@ export default {
         if (res.code === 0) {
           this.pubkey.key = res.data.pubkey
           this.pubkey.r = res.data.r
+
+          this.getCaptcha()
         } else {
           this.$notify.info({
             title: '提示',

+ 1 - 1
src/views/sso/login1.vue

@@ -70,7 +70,7 @@
 </template>
 
 <script>
-import { ServeCaptcha, ServeRegister, ServeSendVerifyCode } from '@/api/auth'
+import { ServeCaptcha, ServeRegister, ServeSendVerifyCode } from '@/api/account'
 import { isMobile } from '@/utils/validate'
 import SmsLock from '@/utils/sms-lock'
 

+ 1 - 1
src/views/sso/register.vue

@@ -113,7 +113,7 @@
 </template>
 
 <script>
-import { ServeCaptcha, ServeRegister, ServeSendVerifyCode } from '@/api/auth'
+import { ServeCaptcha, ServeRegister, ServeSendVerifyCode } from '@/api/account'
 import { isMobile } from '@/utils/validate'
 import SmsLock from '@/utils/sms-lock'