Fix changing password form, session storage

This commit is contained in:
Max Leiter 2022-05-30 16:08:08 -07:00
parent a804b7cb2a
commit c4dea351de
No known key found for this signature in database
GPG key ID: A3512F2F2F17EBDA
5 changed files with 35 additions and 25 deletions

View file

@ -6,7 +6,7 @@
<i class="account"> [{{ message.account }}]</i>
</template>
<template v-if="message.gecos">
<i class="realname"> {{ message.gecos }}</i>
<i class="realname"> {{ message.gecos }} </i>
</template>
has joined the channel
</span>

View file

@ -102,7 +102,7 @@
import socket from "../../js/socket";
import RevealPassword from "../RevealPassword.vue";
import Session from "../Session.vue";
import {computed, defineComponent, onMounted, ref} from "vue";
import {computed, defineComponent, onMounted, PropType, ref} from "vue";
import {useStore} from "../../js/store";
export default defineComponent({
@ -111,9 +111,15 @@ export default defineComponent({
RevealPassword,
Session,
},
setup() {
props: {
settingsForm: {
type: Object as PropType<HTMLFormElement>,
required: true,
},
},
setup(props) {
const store = useStore();
const settingsForm = ref<HTMLFormElement>();
const passwordErrors = {
missing_fields: "Please enter a new password",
password_mismatch: "Both new password fields must match",
@ -143,7 +149,8 @@ export default defineComponent({
});
const changePassword = () => {
const allFields = new FormData(settingsForm.value);
const allFields = new FormData(props.settingsForm);
const data = {
old_password: allFields.get("old_password"),
new_password: allFields.get("new_password"),

View file

@ -7,14 +7,14 @@
<div class="container">
<form ref="settingsForm" autocomplete="off" @change="onChange" @submit.prevent>
<router-view></router-view>
<router-view :settings-form="settingsForm"></router-view>
</form>
</div>
</div>
</template>
<script lang="ts">
import {defineComponent} from "vue";
import {defineComponent, ref} from "vue";
import SidebarToggle from "../SidebarToggle.vue";
import Navigation from "../Settings/Navigation.vue";
import {useStore} from "../../js/store";
@ -27,6 +27,7 @@ export default defineComponent({
},
setup() {
const store = useStore();
const settingsForm = ref<HTMLFormElement>();
const onChange = (event: Event) => {
const ignore = ["old_password", "new_password", "verify_password"];
@ -45,13 +46,12 @@ export default defineComponent({
value = (event.target as HTMLInputElement).value;
}
store.dispatch("settings/update", {name, value, sync: true}).catch(() => {
// no-op
});
void store.dispatch("settings/update", {name, value, sync: true});
};
return {
onChange,
settingsForm,
};
},
});

View file

@ -58,6 +58,7 @@ const router = createRouter({
name: "Account",
path: "account",
component: AccountSettings,
props: true,
},
{
name: "Notifications",

View file

@ -677,18 +677,21 @@ function initializeClient(
const sendSessionList = () => {
// TODO: this should use the ClientSession type currently in client
const sessions = _.map(client.config.sessions, (session, sessionToken) => ({
current: sessionToken === token,
active: _.reduce(
client.attachedClients,
(count, attachedClient) => count + (attachedClient.token === sessionToken ? 1 : 0),
0
),
lastUse: session.lastUse,
ip: session.ip,
agent: session.agent,
token: sessionToken, // TODO: Ideally don't expose actual tokens to the client
}));
const sessions = _.map(client.config.sessions, (session, sessionToken) => {
return {
current: sessionToken === token,
active: _.reduce(
client.attachedClients,
(count, attachedClient) =>
count + (attachedClient.token === sessionToken ? 1 : 0),
0
),
lastUse: session.lastUse,
ip: session.ip,
agent: session.agent,
token: sessionToken, // TODO: Ideally don't expose actual tokens to the client
};
});
socket.emit("sessions:list", sessions);
};
@ -815,7 +818,7 @@ function initializeClient(
void socket.join(client.id?.toString());
const sendInitEvent = (tokenToSend) => {
const sendInitEvent = (tokenToSend: string | null) => {
socket.emit("init", {
active: openChannel,
networks: client.networks.map((network) =>
@ -828,13 +831,12 @@ function initializeClient(
if (Config.values.public) {
sendInitEvent(null);
} else if (token === null) {
} else if (!token) {
client.generateToken((newToken) => {
token = client.calculateTokenHash(newToken);
client.attachedClients[socket.id].token = token;
client.updateSession(token, getClientIp(socket), socket.request);
sendInitEvent(newToken);
});
} else {