2019-03-03 17:47:49 +00:00
|
|
|
<template>
|
2019-12-12 11:37:53 +00:00
|
|
|
<div class="session-item">
|
|
|
|
<div class="session-item-info">
|
|
|
|
<strong>{{ session.agent }}</strong>
|
2019-03-03 17:47:49 +00:00
|
|
|
|
2019-12-12 11:37:53 +00:00
|
|
|
<a :href="'https://ipinfo.io/' + session.ip" target="_blank" rel="noopener">{{
|
|
|
|
session.ip
|
|
|
|
}}</a>
|
2019-03-03 17:47:49 +00:00
|
|
|
|
2020-03-17 15:36:13 +00:00
|
|
|
<p v-if="session.active > 1" class="session-usage">
|
|
|
|
Active in {{ session.active }} browsers
|
|
|
|
</p>
|
|
|
|
<p v-else-if="!session.current && !session.active" class="session-usage">
|
|
|
|
Last used on <time>{{ lastUse }}</time>
|
|
|
|
</p>
|
2019-12-12 11:37:53 +00:00
|
|
|
</div>
|
|
|
|
<div class="session-item-btn">
|
|
|
|
<button class="btn" @click.prevent="signOut">
|
|
|
|
<template v-if="session.current">Sign out</template>
|
|
|
|
<template v-else>Revoke</template>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-03-03 17:47:49 +00:00
|
|
|
</template>
|
|
|
|
|
2020-03-17 15:36:13 +00:00
|
|
|
<style>
|
|
|
|
.session-list .session-item {
|
|
|
|
display: flex;
|
|
|
|
font-size: 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.session-list .session-item-info {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
flex-grow: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.session-list .session-item-btn {
|
|
|
|
flex-shrink: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.session-list .session-usage {
|
|
|
|
font-style: italic;
|
|
|
|
color: var(--body-color-muted);
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import {computed, defineComponent, PropType} from "vue";
|
2020-01-08 09:11:44 +00:00
|
|
|
import localetime from "../js/helpers/localetime";
|
2019-11-16 17:24:03 +00:00
|
|
|
import Auth from "../js/auth";
|
|
|
|
import socket from "../js/socket";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {ClientSession} from "../js/store";
|
2019-03-03 17:47:49 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default defineComponent({
|
2019-03-03 17:47:49 +00:00
|
|
|
name: "Session",
|
|
|
|
props: {
|
2022-06-19 00:25:21 +00:00
|
|
|
session: {
|
|
|
|
type: Object as PropType<ClientSession>,
|
|
|
|
required: true,
|
2020-01-08 09:11:44 +00:00
|
|
|
},
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
setup(props) {
|
|
|
|
const lastUse = computed(() => {
|
|
|
|
return localetime(props.session.lastUse);
|
|
|
|
});
|
|
|
|
|
|
|
|
const signOut = () => {
|
|
|
|
if (!props.session.current) {
|
|
|
|
socket.emit("sign-out", props.session.token);
|
2019-03-03 17:47:49 +00:00
|
|
|
} else {
|
|
|
|
socket.emit("sign-out");
|
|
|
|
Auth.signout();
|
|
|
|
}
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
lastUse,
|
|
|
|
signOut,
|
|
|
|
};
|
2019-03-03 17:47:49 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2019-03-03 17:47:49 +00:00
|
|
|
</script>
|