2022-02-19 00:45:25 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
v-if="
|
2022-06-19 00:25:21 +00:00
|
|
|
!store.state.serverConfiguration?.public &&
|
|
|
|
!store.state.serverConfiguration?.ldapEnabled
|
2022-02-19 00:45:25 +00:00
|
|
|
"
|
|
|
|
id="change-password"
|
|
|
|
role="group"
|
|
|
|
aria-labelledby="label-change-password"
|
|
|
|
>
|
|
|
|
<h2 id="label-change-password">Change password</h2>
|
|
|
|
<div class="password-container">
|
|
|
|
<label for="current-password" class="sr-only"> Enter current password </label>
|
|
|
|
<RevealPassword v-slot:default="slotProps">
|
|
|
|
<input
|
|
|
|
id="current-password"
|
2023-05-23 06:18:20 +00:00
|
|
|
v-model="old_password"
|
2022-02-19 00:45:25 +00:00
|
|
|
autocomplete="current-password"
|
|
|
|
:type="slotProps.isVisible ? 'text' : 'password'"
|
|
|
|
name="old_password"
|
|
|
|
class="input"
|
|
|
|
placeholder="Enter current password"
|
|
|
|
/>
|
|
|
|
</RevealPassword>
|
|
|
|
</div>
|
|
|
|
<div class="password-container">
|
|
|
|
<label for="new-password" class="sr-only"> Enter desired new password </label>
|
|
|
|
<RevealPassword v-slot:default="slotProps">
|
|
|
|
<input
|
|
|
|
id="new-password"
|
2023-05-23 06:18:20 +00:00
|
|
|
v-model="new_password"
|
2022-02-19 00:45:25 +00:00
|
|
|
:type="slotProps.isVisible ? 'text' : 'password'"
|
|
|
|
name="new_password"
|
|
|
|
autocomplete="new-password"
|
|
|
|
class="input"
|
|
|
|
placeholder="Enter desired new password"
|
|
|
|
/>
|
|
|
|
</RevealPassword>
|
|
|
|
</div>
|
|
|
|
<div class="password-container">
|
|
|
|
<label for="new-password-verify" class="sr-only"> Repeat new password </label>
|
|
|
|
<RevealPassword v-slot:default="slotProps">
|
|
|
|
<input
|
|
|
|
id="new-password-verify"
|
2023-05-23 06:18:20 +00:00
|
|
|
v-model="verify_password"
|
2022-02-19 00:45:25 +00:00
|
|
|
:type="slotProps.isVisible ? 'text' : 'password'"
|
|
|
|
name="verify_password"
|
|
|
|
autocomplete="new-password"
|
|
|
|
class="input"
|
|
|
|
placeholder="Repeat new password"
|
|
|
|
/>
|
|
|
|
</RevealPassword>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-if="passwordChangeStatus && passwordChangeStatus.success"
|
|
|
|
class="feedback success"
|
|
|
|
>
|
|
|
|
Successfully updated your password
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-else-if="passwordChangeStatus && passwordChangeStatus.error"
|
|
|
|
class="feedback error"
|
|
|
|
>
|
|
|
|
{{ passwordErrors[passwordChangeStatus.error] }}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<button type="submit" class="btn" @click.prevent="changePassword">
|
|
|
|
Change password
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<div v-if="!store.state.serverConfiguration?.public" class="session-list" role="group">
|
2022-02-19 00:45:25 +00:00
|
|
|
<h2>Sessions</h2>
|
|
|
|
|
|
|
|
<h3>Current session</h3>
|
|
|
|
<Session v-if="currentSession" :session="currentSession" />
|
|
|
|
|
|
|
|
<template v-if="activeSessions.length > 0">
|
|
|
|
<h3>Active sessions</h3>
|
|
|
|
<Session
|
|
|
|
v-for="session in activeSessions"
|
|
|
|
:key="session.token"
|
|
|
|
:session="session"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<h3>Other sessions</h3>
|
2022-06-19 00:25:21 +00:00
|
|
|
<p v-if="store.state.sessions.length === 0">Loading…</p>
|
2022-02-19 00:45:25 +00:00
|
|
|
<p v-else-if="otherSessions.length === 0">
|
|
|
|
<em>You are not currently logged in to any other device.</em>
|
|
|
|
</p>
|
|
|
|
<Session
|
|
|
|
v-for="session in otherSessions"
|
|
|
|
v-else
|
|
|
|
:key="session.token"
|
|
|
|
:session="session"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
2022-02-19 00:45:25 +00:00
|
|
|
import socket from "../../js/socket";
|
|
|
|
import RevealPassword from "../RevealPassword.vue";
|
|
|
|
import Session from "../Session.vue";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {computed, defineComponent, onMounted, PropType, ref} from "vue";
|
|
|
|
import {useStore} from "../../js/store";
|
2022-02-19 00:45:25 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default defineComponent({
|
2022-02-19 00:45:25 +00:00
|
|
|
name: "UserSettings",
|
|
|
|
components: {
|
|
|
|
RevealPassword,
|
|
|
|
Session,
|
|
|
|
},
|
2023-05-23 06:18:20 +00:00
|
|
|
setup() {
|
2022-06-19 00:25:21 +00:00
|
|
|
const store = useStore();
|
|
|
|
|
|
|
|
const passwordErrors = {
|
2023-05-23 06:24:20 +00:00
|
|
|
missing_fields: "Please fill in all fields",
|
2022-06-19 00:25:21 +00:00
|
|
|
password_mismatch: "Both new password fields must match",
|
|
|
|
password_incorrect: "The current password field does not match your account password",
|
|
|
|
update_failed: "Failed to update your password",
|
|
|
|
};
|
|
|
|
|
|
|
|
const passwordChangeStatus = ref<{
|
|
|
|
success: boolean;
|
|
|
|
error: keyof typeof passwordErrors;
|
|
|
|
}>();
|
|
|
|
|
2023-05-23 06:18:20 +00:00
|
|
|
const old_password = ref("");
|
|
|
|
const new_password = ref("");
|
|
|
|
const verify_password = ref("");
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const currentSession = computed(() => {
|
|
|
|
return store.state.sessions.find((item) => item.current);
|
|
|
|
});
|
|
|
|
|
|
|
|
const activeSessions = computed(() => {
|
|
|
|
return store.state.sessions.filter((item) => !item.current && item.active > 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
const otherSessions = computed(() => {
|
|
|
|
return store.state.sessions.filter((item) => !item.current && !item.active);
|
|
|
|
});
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
socket.emit("sessions:get");
|
|
|
|
});
|
|
|
|
|
|
|
|
const changePassword = () => {
|
2022-02-19 00:45:25 +00:00
|
|
|
const data = {
|
2023-05-23 06:18:20 +00:00
|
|
|
old_password: old_password.value,
|
|
|
|
new_password: new_password.value,
|
|
|
|
verify_password: verify_password.value,
|
2022-02-19 00:45:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!data.old_password || !data.new_password || !data.verify_password) {
|
2022-06-19 00:25:21 +00:00
|
|
|
passwordChangeStatus.value = {
|
2022-02-19 00:45:25 +00:00
|
|
|
success: false,
|
|
|
|
error: "missing_fields",
|
|
|
|
};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.new_password !== data.verify_password) {
|
2022-06-19 00:25:21 +00:00
|
|
|
passwordChangeStatus.value = {
|
2022-02-19 00:45:25 +00:00
|
|
|
success: false,
|
|
|
|
error: "password_mismatch",
|
|
|
|
};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
socket.once("change-password", (response) => {
|
2022-06-19 00:25:21 +00:00
|
|
|
// TODO type
|
|
|
|
passwordChangeStatus.value = response as any;
|
2022-02-19 00:45:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.emit("change-password", data);
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
store,
|
|
|
|
passwordChangeStatus,
|
|
|
|
passwordErrors,
|
|
|
|
currentSession,
|
|
|
|
activeSessions,
|
|
|
|
otherSessions,
|
|
|
|
changePassword,
|
2023-05-23 06:18:20 +00:00
|
|
|
old_password,
|
|
|
|
new_password,
|
|
|
|
verify_password,
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
2022-02-19 00:45:25 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2022-02-19 00:45:25 +00:00
|
|
|
</script>
|