remove autopassword param on login.

This commit is contained in:
m1k1o 2021-03-10 21:39:52 +01:00
parent d763895665
commit d3a16ea212

View File

@ -151,30 +151,49 @@
@Component({ name: 'neko-connect' }) @Component({ name: 'neko-connect' })
export default class extends Vue { export default class extends Vue {
private autoPassword = new URL(location.href).searchParams.get('pwd')
private displayname = '' private displayname = ''
private password = '' private password = this.autoPassword
mounted() { mounted() {
if (this.$accessor.displayname !== '' && this.$accessor.password !== '') { if (this.$accessor.displayname !== '' && this.$accessor.password !== '') {
this.$accessor.login({ displayname: this.$accessor.displayname, password: this.$accessor.password }) this.$accessor.login({ displayname: this.$accessor.displayname, password: this.$accessor.password })
} }
} }
get autoPassword() {
return new URL(location.href).searchParams.get('pwd')
}
get connecting() { get connecting() {
return this.$accessor.connecting return this.$accessor.connecting
} }
async login() { removeUrlParam(param: string) {
let password = this.password let url = document.location.href
if (this.autoPassword) { let urlparts = url.split('?')
password = this.autoPassword
if (urlparts.length >= 2) {
let urlBase = urlparts.shift()
let queryString = urlparts.join('?')
let prefix = encodeURIComponent(param) + '='
let pars = queryString.split(/[&;]/g)
for (let i = pars.length; i-- > 0; ) {
if (pars[i].lastIndexOf(prefix, 0) !== -1) {
pars.splice(i, 1)
}
} }
url = urlBase + (pars.length > 0 ? '?' + pars.join('&') : '')
window.history.pushState('', document.title, url)
}
}
async login() {
try { try {
await this.$accessor.login({ displayname: this.displayname, password }) await this.$accessor.login({ displayname: this.displayname, password: this.password, })
if (this.autoPassword) {
this.removeUrlParam('pwd')
this.autoPassword = ''
}
} catch (err) { } catch (err) {
this.$swal({ this.$swal({
title: this.$t('connect.error') as string, title: this.$t('connect.error') as string,