create user token via cli

This commit is contained in:
MaysWind
2024-11-09 23:43:27 +08:00
parent 79fd9070e4
commit b8253b6dcc
6 changed files with 158 additions and 63 deletions
@@ -106,10 +106,10 @@
v-for="session in sessions">
<td class="text-sm">
<v-icon start :icon="session.icon"/>
{{ session.deviceType }}
{{ $t(session.isCurrent ? 'Current' : 'Other Device') }}
</td>
<td class="text-sm">{{ session.deviceInfo }}</td>
<td class="text-sm">{{ session.lastSeen }}</td>
<td class="text-sm">{{ session.lastSeenDateTime }}</td>
<td class="text-sm text-right">
<v-btn density="comfortable" color="error" variant="tonal"
:disabled="session.isCurrent || loadingSession"
@@ -136,7 +136,7 @@ import { useUserStore } from '@/stores/user.js';
import { useTokensStore } from '@/stores/token.js';
import { isEquals } from '@/lib/common.js';
import { parseDeviceInfo, parseUserAgent } from '@/lib/misc.js';
import { parseSessionInfo } from '@/lib/misc.js';
import {
mdiRefresh,
@@ -144,6 +144,7 @@ import {
mdiTablet,
mdiWatch,
mdiTelevision,
mdiConsole,
mdiDevices
} from '@mdi/js';
@@ -187,15 +188,10 @@ export default {
for (let i = 0; i < this.tokens.length; i++) {
const token = this.tokens[i];
sessions.push({
tokenId: token.tokenId,
isCurrent: token.isCurrent,
deviceType: this.$t(token.isCurrent ? 'Current' : 'Other Device'),
deviceInfo: parseDeviceInfo(token.userAgent),
icon: this.getTokenIcon(token),
lastSeen: token.lastSeen ? this.$locale.formatUnixTimeToLongDateTime(this.userStore, token.lastSeen) : '-'
});
const sessionInfo = parseSessionInfo(token);
sessionInfo.icon = this.getTokenIcon(sessionInfo.deviceType);
sessionInfo.lastSeenDateTime = sessionInfo.lastSeen ? this.$locale.formatUnixTimeToLongDateTime(this.userStore, sessionInfo.lastSeen) : '-';
sessions.push(sessionInfo);
}
return sessions;
@@ -335,21 +331,17 @@ export default {
});
});
},
getTokenIcon(token) {
const ua = parseUserAgent(token.userAgent);
if (!ua || !ua.device) {
return mdiDevices;
}
if (ua.device.type === 'mobile') {
getTokenIcon(deviceType) {
if (deviceType === 'phone') {
return mdiCellphone;
} else if (ua.device.type === 'wearable') {
} else if (deviceType === 'wearable') {
return mdiWatch;
} else if (ua.device.type === 'tablet') {
} else if (deviceType === 'tablet') {
return mdiTablet;
} else if (ua.device.type === 'smarttv') {
} else if (deviceType === 'tv') {
return mdiTelevision;
} else if (deviceType === 'cli') {
return mdiConsole;
} else {
return mdiDevices;
}
+15 -24
View File
@@ -24,7 +24,7 @@
<f7-list strong inset dividers media-list class="margin-top" v-else-if="!loading">
<f7-list-item class="list-item-media-valign-middle" swipeout
:id="session.domId"
:title="session.deviceType"
:title="$t(session.isCurrent ? 'Current' : 'Other Device')"
:text="session.deviceInfo"
:key="session.tokenId"
v-for="session in sessions">
@@ -32,7 +32,7 @@
<f7-icon :f7="session.icon"></f7-icon>
</template>
<template #after>
<small>{{ session.lastSeen }}</small>
<small>{{ session.lastSeenDateTime }}</small>
</template>
<f7-swipeout-actions right v-if="!session.isCurrent">
<f7-swipeout-button color="red" :text="$t('Log Out')" @click="revoke(session)"></f7-swipeout-button>
@@ -48,7 +48,7 @@ import { useUserStore } from '@/stores/user.js';
import { useTokensStore } from '@/stores/token.js';
import { isEquals } from '@/lib/common.js';
import { parseDeviceInfo, parseUserAgent } from '@/lib/misc.js';
import { parseSessionInfo } from '@/lib/misc.js';
import { onSwipeoutDeleted } from '@/lib/ui.mobile.js';
@@ -74,16 +74,11 @@ export default {
for (let i = 0; i < this.tokens.length; i++) {
const token = this.tokens[i];
sessions.push({
tokenId: token.tokenId,
domId: this.getTokenDomId(token.tokenId),
isCurrent: token.isCurrent,
deviceType: this.$t(token.isCurrent ? 'Current' : 'Other Device'),
deviceInfo: parseDeviceInfo(token.userAgent),
icon: this.getTokenIcon(token),
lastSeen: token.lastSeen ? this.$locale.formatUnixTimeToLongDateTime(this.userStore, token.lastSeen) : '-'
});
const sessionInfo = parseSessionInfo(token);
sessionInfo.domId = this.getTokenDomId(sessionInfo.tokenId);
sessionInfo.icon = this.getTokenIcon(sessionInfo.deviceType);
sessionInfo.lastSeenDateTime = sessionInfo.lastSeen ? this.$locale.formatUnixTimeToLongDateTime(this.userStore, sessionInfo.lastSeen) : '-';
sessions.push(sessionInfo);
}
return sessions;
@@ -191,21 +186,17 @@ export default {
});
});
},
getTokenIcon(token) {
const ua = parseUserAgent(token.userAgent);
if (!ua || !ua.device) {
return 'device_desktop';
}
if (ua.device.type === 'mobile') {
getTokenIcon(deviceType) {
if (deviceType === 'phone') {
return 'device_phone_portrait';
} else if (ua.device.type === 'wearable') {
} else if (deviceType === 'wearable') {
return 'device_phone_portrait';
} else if (ua.device.type === 'tablet') {
} else if (deviceType === 'tablet') {
return 'device_tablet_portrait';
} else if (ua.device.type === 'smarttv') {
} else if (deviceType === 'tv') {
return 'tv';
} else if (deviceType === 'cli') {
return 'chevron_left_slash_chevron_right';
} else {
return 'device_desktop';
}