save settings with password confirmation

This commit is contained in:
Simon Vieille 2025-04-14 22:44:00 +02:00
commit b98bbd1053
Signed by untrusted user: deblan
GPG key ID: 579388D585F70417
2 changed files with 52 additions and 17 deletions

View file

@ -13,13 +13,14 @@
<div
v-if="error"
id="error"
></div>
>{{ error }}</div>
</div>
</template>
<script setup>
import { NcButton, NcLoadingIcon } from '@nextcloud/vue'
import { ref } from 'vue'
import { waitPasswordConfirmation } from '../../lib/setting.js'
const loading = ref(false)
const error = ref(null)
@ -62,25 +63,33 @@ const save = async () => {
}
}
for (let key in data) {
let value = data[key]
waitPasswordConfirmation()
.then(() => {
for (let key in data) {
let value = data[key]
if (Array.isArray(value) || typeof value === 'object') {
value = JSON.stringify(value)
} else if (typeof value === 'boolean') {
value = value ? 1 : 0
}
if (Array.isArray(value) || typeof value === 'object') {
value = JSON.stringify(value)
} else if (typeof value === 'boolean') {
value = value ? 1 : 0
}
OCP.AppConfig.setValue('side_menu', key, value, {
success() {
update()
},
error() {
error.value = `Error while saving ${key}`
update()
},
OCP.AppConfig.setValue('side_menu', key, value, {
success() {
update()
},
error() {
error.value = `Error while saving ${key}`
update()
},
})
}
})
.catch(() => {
counter = 0
loading.value = false
error.value = null
})
}
}
</script>

26
src/lib/setting.js Normal file
View file

@ -0,0 +1,26 @@
const waitPasswordConfirmation = async () => {
let tries = 0
return new Promise((resolve, reject) => {
const execute = () => {
if (!OC.PasswordConfirmation.requiresPasswordConfirmation()) {
resolve()
return
}
OC.PasswordConfirmation.requirePasswordConfirmation(() => {})
if (++tries !== 10) {
setTimeout(() => {
execute()
}, 2000)
} else {
reject()
}
}
execute()
})
}
export { waitPasswordConfirmation }