[editor] Prevent adding invalid usernames as channel / editor

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-12-31 17:12:07 +01:00
parent 0afafa535d
commit 192dcb7f46
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
2 changed files with 18 additions and 0 deletions

View file

@ -22,3 +22,5 @@ export const NOTIFY_CONFIG_RELOAD = 'configReload'
export const NOTIFY_ERROR = 'error' export const NOTIFY_ERROR = 'error'
export const NOTIFY_FETCH_ERROR = 'fetchError' export const NOTIFY_FETCH_ERROR = 'fetchError'
export const NOTIFY_LOADING_DATA = 'loadingData' export const NOTIFY_LOADING_DATA = 'loadingData'
export const REGEXP_USER = /^[a-z0-9_]{4,25}$/

View file

@ -56,11 +56,13 @@
<b-input-group> <b-input-group>
<b-form-input <b-form-input
v-model="models.addChannel" v-model="models.addChannel"
:state="!!validateUserName(models.addChannel)"
@keyup.enter="addChannel" @keyup.enter="addChannel"
/> />
<b-input-group-append> <b-input-group-append>
<b-button <b-button
variant="success" variant="success"
:disabled="!validateUserName(models.addChannel)"
@click="addChannel" @click="addChannel"
> >
<font-awesome-icon <font-awesome-icon
@ -117,11 +119,13 @@
<b-input-group> <b-input-group>
<b-form-input <b-form-input
v-model="models.addEditor" v-model="models.addEditor"
:state="!!validateUserName(models.addEditor)"
@keyup.enter="addEditor" @keyup.enter="addEditor"
/> />
<b-input-group-append> <b-input-group-append>
<b-button <b-button
variant="success" variant="success"
:disabled="!validateUserName(models.addEditor)"
@click="addEditor" @click="addEditor"
> >
<font-awesome-icon <font-awesome-icon
@ -416,6 +420,10 @@ export default {
methods: { methods: {
addChannel() { addChannel() {
if (!this.validateUserName(this.models.addChannel)) {
return
}
this.generalConfig.channels.push(this.models.addChannel.replace(/^#*/, '')) this.generalConfig.channels.push(this.models.addChannel.replace(/^#*/, ''))
this.models.addChannel = '' this.models.addChannel = ''
@ -423,6 +431,10 @@ export default {
}, },
addEditor() { addEditor() {
if (!this.validateUserName(this.models.addEditor)) {
return
}
this.fetchProfile(this.models.addEditor) this.fetchProfile(this.models.addEditor)
this.generalConfig.bot_editors.push(this.models.addEditor) this.generalConfig.bot_editors.push(this.models.addEditor)
this.models.addEditor = '' this.models.addEditor = ''
@ -566,6 +578,10 @@ export default {
}) })
.catch(err => this.$bus.$emit(constants.NOTIFY_FETCH_ERROR, err)) .catch(err => this.$bus.$emit(constants.NOTIFY_FETCH_ERROR, err))
}, },
validateUserName(user) {
return user.match(constants.REGEXP_USER)
},
}, },
mounted() { mounted() {