From 108ac79443eed38f2f76464038cc58ff8d954b75 Mon Sep 17 00:00:00 2001 From: m1k1o Date: Fri, 12 Mar 2021 22:24:52 +0100 Subject: [PATCH] autologin with URL pwd first. --- client/src/components/connect.vue | 32 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/client/src/components/connect.vue b/client/src/components/connect.vue index 26b4511..ab52357 100644 --- a/client/src/components/connect.vue +++ b/client/src/components/connect.vue @@ -151,14 +151,21 @@ @Component({ name: 'neko-connect' }) export default class extends Vue { - private autoPassword = new URL(location.href).searchParams.get('pwd') + private autoPassword: string | null = new URL(location.href).searchParams.get('pwd') private displayname: string = '' - private password: string = this.autoPassword || '' + private password: string = '' mounted() { - if (this.$accessor.displayname !== '' && this.$accessor.password !== '') { - this.$accessor.login({ displayname: this.$accessor.displayname, password: this.$accessor.password }) + let password = this.$accessor.password + if (this.autoPassword !== null) { + this.removeUrlParam('pwd') + password = this.autoPassword + } + + if (this.$accessor.displayname !== '' && password !== '') { + this.$accessor.login({ displayname: this.$accessor.displayname, password }) + this.autoPassword = null } } @@ -188,16 +195,15 @@ } async login() { - try { - await this.$accessor.login({ - displayname: this.displayname, - password: this.password, - }) + let password = this.password + if (this.autoPassword !== null) { + password = this.autoPassword + } - if (this.autoPassword) { - this.removeUrlParam('pwd') - this.autoPassword = '' - } + try { + await this.$accessor.login({ displayname: this.displayname, password }) + + this.autoPassword = null } catch (err) { this.$swal({ title: this.$t('connect.error') as string,