From f88c19343fdcbc22aa1150f0944a463af76da9cd Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 14 Jan 2021 08:58:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=9C=9F=E5=AE=9Eip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/store/modules/user.js | 49 +++++++++++++++++--------------- server/apps/ability/views.py | 2 +- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/client/src/store/modules/user.js b/client/src/store/modules/user.js index 185db55..c755f77 100644 --- a/client/src/store/modules/user.js +++ b/client/src/store/modules/user.js @@ -97,10 +97,28 @@ const actions = { const { data } = response if (!data) { - reject('验证失败,重新登录.') - } - - const { perms, name, avatar } = data + getInfo(state.token).then(response => { + const { data } = response + + if (!data) { + reject('验证失败,重新登录.') + } + + const { perms, name, avatar } = data + + // perms must be a non-empty array + if (!perms || perms.length <= 0) { + reject('没有任何权限!') + } + + commit('SET_PERMS', perms) + commit('SET_NAME', name) + commit('SET_AVATAR', avatar) + resolve(data) + }).catch(error => { + reject(error)}) + }else{ + const { perms, name, avatar } = data // perms must be a non-empty array if (!perms || perms.length <= 0) { @@ -111,26 +129,11 @@ const actions = { commit('SET_NAME', name) commit('SET_AVATAR', avatar) resolve(data) + } + + }).catch(error => { - getInfo(state.token).then(response => { - const { data } = response - - if (!data) { - reject('验证失败,重新登录.') - } - - const { perms, name, avatar } = data - - // perms must be a non-empty array - if (!perms || perms.length <= 0) { - reject('没有任何权限!') - } - - commit('SET_PERMS', perms) - commit('SET_NAME', name) - commit('SET_AVATAR', avatar) - resolve(data) - }).catch(e=>{}) + reject(error) }) }) }, diff --git a/server/apps/ability/views.py b/server/apps/ability/views.py index 267a45d..763c7b0 100644 --- a/server/apps/ability/views.py +++ b/server/apps/ability/views.py @@ -27,7 +27,7 @@ class RecordMixin(): """ user = request.user if request.method == 'GET': - QueryRecord.objects.create(user=user,path=request.path,ip=request.META.get('REMOTE_ADDR'),method=\ + QueryRecord.objects.create(user=user,path=request.path,ip=request.META.get('HTTP_X_FORWARDED_FOR'),method=\ request.method,search=request.query_params.get('search',None),query=request.query_params) class QueryRecordListViewSet(ListModelMixin, GenericViewSet):