add revoke all sessions in device & session page

This commit is contained in:
MaysWind
2020-11-15 20:58:51 +08:00
parent fa76067881
commit 73fecf9c63
7 changed files with 115 additions and 7 deletions
+3
View File
@@ -126,6 +126,9 @@ export default {
tokenId
});
},
revokeAllTokens: () => {
return axios.post('v1/tokens/revokeAll.json');
},
getProfile: () => {
return axios.get('v1/users/profile/get.json');
},
+4
View File
@@ -358,11 +358,15 @@ export default {
'Your profile has been successfully updated': 'Your profile has been successfully updated',
'Unable to update user profile': 'Unable to update user profile',
'Device & Sessions': 'Device & Sessions',
'Logout All': 'Logout All',
'Unable to get session list': 'Unable to get session list',
'Current': 'Current',
'Other Device': 'Other Device',
'Are you sure you want to logout from this session?': 'Are you sure you want to logout from this session?',
'Unable to logout from this session': 'Unable to logout from this session',
'Are you sure you want to logout all other sessions?': 'Are you sure you want to logout all other sessions?',
'You have logged out all other sessions': 'You have logged out all other sessions',
'Unable to logout all other sessions': 'Unable to logout all other sessions',
'Regenerate Backup Codes': 'Regenerate Backup Codes',
'Please use two factor authentication app scan the below qrcode and input current passcode': 'Please use two factor authentication app scan the below qrcode and input current passcode',
'Please enter your current password when disable two factor authentication': 'Please enter your current password when disable two factor authentication',
+4
View File
@@ -358,11 +358,15 @@ export default {
'Your profile has been successfully updated': '您的用户信息更新成功',
'Unable to update user profile': '无法更新用户信息',
'Device & Sessions': '设备和会话',
'Logout All': '注销全部',
'Unable to get session list': '无法获取会话列表',
'Current': '当前',
'Other Device': '其他设备',
'Are you sure you want to logout from this session?': '您确定是否要退出该会话?',
'Unable to logout from this session': '无法退出该会话',
'Are you sure you want to logout all other sessions?': '您确定是否要退出其他所有会话?',
'You have logged out all other sessions': '您已经退出其他所有会话',
'Unable to logout all other sessions': '无法退出其他所有会话',
'Regenerate Backup Codes': '重新生成备用码',
'Please use two factor authentication app scan the below qrcode and input current passcode': '请使用两步验证应用扫描下方的二维码并输入当前的验证码',
'Please enter your current password when disable two factor authentication': '禁用两步验证时需要输入您的当前密码',
+44 -1
View File
@@ -1,6 +1,12 @@
<template>
<f7-page ptr @ptr:refresh="reload">
<f7-navbar :title="$t('Device & Sessions')" :back-link="$t('Back')"></f7-navbar>
<f7-navbar>
<f7-nav-left :back-link="$t('Back')"></f7-nav-left>
<f7-nav-title :title="$t('Device & Sessions')"></f7-nav-title>
<f7-nav-right>
<f7-link :class="{ 'disabled': tokens.length < 2 }" :text="$t('Logout All')" @click="revokeAll"></f7-link>
</f7-nav-right>
</f7-navbar>
<f7-card class="skeleton-text" v-if="loading">
<f7-card-content :padding="false">
@@ -126,6 +132,43 @@ export default {
}
});
});
},
revokeAll() {
const self = this;
if (self.tokens.length < 2) {
return;
}
self.$confirm('Are you sure you want to logout all other sessions?', () => {
self.$showLoading();
self.$services.revokeAllTokens().then(response => {
self.$hideLoading();
const data = response.data;
if (!data || !data.success || !data.result) {
self.$alert('Unable to logout all other sessions');
return;
}
for (let i = self.tokens.length - 1; i >= 0; i--) {
if (!self.tokens[i].isCurrent) {
self.tokens.splice(i, 1);
}
}
self.$toast('You have logged out all other sessions');
}).catch(error => {
self.$hideLoading();
if (error.response && error.response.data && error.response.data.errorMessage) {
self.$alert({error: error.response.data});
} else if (!error.processed) {
self.$alert('Unable to logout all other sessions');
}
});
});
}
},
filters: {