From e80be6375d4781093c6093698933b0aea9f94876 Mon Sep 17 00:00:00 2001 From: chaosBreaking Date: Mon, 7 Oct 2019 20:20:46 +0800 Subject: [PATCH] token --- .gitignore | 2 ++ ConfigCustom.js | 8 -------- src/router.js | 34 +++++++++++++--------------------- src/services/axios.js | 2 +- src/store/modules/login.js | 7 +++++-- 5 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 ConfigCustom.js diff --git a/.gitignore b/.gitignore index 2ac0a06..a958de5 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ yarn-error.log* *.njsproj *.sln *.sw* + +configSec.js diff --git a/ConfigCustom.js b/ConfigCustom.js deleted file mode 100644 index 548a176..0000000 --- a/ConfigCustom.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports={ - // 如果使用 https 协议,必须填写以下内容,或在命令行参数中设置: - // sslType: 'greenlock', - // sslDomainList: [''], - // sslKey: '/etc/letsencrypt/live/test.bittic.net/privkey.pem', // ssl key file, - // sslCert: '/etc/letsencrypt/live/test.bittic.net/fullchain.pem', // ssl cert file, - // sslCA: '/etc/letsencrypt/live/test.bittic.net/bundle.crt', // ssl ca file, -} diff --git a/src/router.js b/src/router.js index fc2b7a4..13ea784 100644 --- a/src/router.js +++ b/src/router.js @@ -32,14 +32,6 @@ const router = new Router({ path: 'network', component: Network, }, - { - path: 'chain', - component: Chain, - }, - { - path: 'market', - component: Market, - }, { path: '*', redirect: 'owner', @@ -49,18 +41,18 @@ const router = new Router({ ], }) -// router.beforeEach((to, _, next) => { -// const loginPage = to.path === '/login' -// const signed = store.getters.isLogin -// if (!loginPage && !signed) { -// next('/login') -// return -// } -// if (loginPage && signed) { -// next('/home') -// return -// } -// next() -// }) +router.beforeEach((to, _, next) => { + const loginPage = to.path === '/login' + const signed = store.getters.isLogin + if (!loginPage && !signed) { + next('/login') + return + } + if (loginPage && signed) { + next('/home') + return + } + next() +}) export default router diff --git a/src/services/axios.js b/src/services/axios.js index d0a9cf4..7f3c7bb 100644 --- a/src/services/axios.js +++ b/src/services/axios.js @@ -2,7 +2,7 @@ import axios from 'axios' // import app from './app' // let baseURL = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/api/` // let baseURL = `${location.protocol}//${location.hostname}:80/api/` -let baseURL = `http://localhost:80/v1/` +let baseURL = `https://server.vic.yuanjin.net/v1/` // 控制台应当默认访问控制台所在主机(localhost 或者 window.location.hostname)的 TIC后台,或者让用户在控制台启动时,自己设置一个节点主机。 axios.defaults.baseURL = baseURL diff --git a/src/store/modules/login.js b/src/store/modules/login.js index 7f4506a..c1b09b0 100644 --- a/src/store/modules/login.js +++ b/src/store/modules/login.js @@ -5,6 +5,7 @@ import _ from 'lodash' import ticCrypto from 'tic.crypto' import axios from 'axios' import * as Ticrypto from 'tic.crypto' +import { tokenSec } from '../../../configSec' export default { namespaced: true, @@ -46,10 +47,12 @@ export default { actions: { async login({ state, commit }) { - console.log(state) commit('updateSign', true) const passwd = Ticrypto.hash(state.passwd) - let result = await axios.post('admin/in', { name: state.username, passwd }) + const ts = Date.now() + const path = '/admin/in' + const sig = ticCrypto.hash(ts + path + tokenSec, { hasher: 'md5' }) + let result = await axios.post('admin/in', { name: state.username, passwd }, { headers: { ts, sig } }) commit('updateSign', false) if (result.data.code === 0) { commit('updateAccount', result.data.data, { root: true })