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