Use nextcloud-password-confirmation

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-11-12 11:54:56 +01:00
parent 13eae29509
commit 89e5ec4183
No known key found for this signature in database
GPG key ID: 60C25B8C072916CF
6 changed files with 26 additions and 45 deletions

View file

@ -1761,7 +1761,7 @@ OC.PasswordConfirmation = {
/**
* @param {function} callback
*/
requirePasswordConfirmation: function(callback, options) {
requirePasswordConfirmation: function(callback, options, rejectCallback) {
options = typeof options !== 'undefined' ? options : {};
var defaults = {
title: t('core','Authentication required'),
@ -1785,6 +1785,8 @@ OC.PasswordConfirmation = {
function (result, password) {
if (result && password !== '') {
self._confirmPassword(password, config);
} else if (_.isFunction(rejectCallback)) {
rejectCallback()
}
},
true,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "settings",
"version": "1.2.3",
"version": "1.2.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -4003,6 +4003,11 @@
"integrity": "sha512-vdqTKI9GBIYcAEbFAcpKPErKINfPF5zIuz3/niBfq8WUZjpT2tytLlFVrBgWdOtqI4uaA/Rb6No0hux39XXDuw==",
"dev": true
},
"nextcloud-password-confirmation": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/nextcloud-password-confirmation/-/nextcloud-password-confirmation-0.4.0.tgz",
"integrity": "sha512-5RNNHP8ymxtqOEwirc4n3uv9uAga2V6wUZ7ns7mQrQQtFh/SLEX8ogSsqxquJWZ7+Jc9gVJSeRcRMLoAag966A=="
},
"nextcloud-vue": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/nextcloud-vue/-/nextcloud-vue-0.1.5.tgz",

View file

@ -1,7 +1,7 @@
{
"name": "settings",
"description": "Nextcloud settings",
"version": "1.2.3",
"version": "1.2.4",
"author": "John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>",
"license": "AGPL3",
"private": true,
@ -13,6 +13,7 @@
"dependencies": {
"@babel/polyfill": "^7.0.0",
"axios": "^0.18.0",
"nextcloud-password-confirmation": "^0.4.0",
"nextcloud-vue": "^0.1.5",
"v-tooltip": "^2.0.0-rc.33",
"vue": "^2.5.17",

View file

@ -20,7 +20,8 @@
*
*/
import axios from 'axios';
import axios from 'axios'
import confirmPassword from 'nextcloud-password-confirmation'
const requestToken = document.getElementsByTagName('head')[0].getAttribute('data-requesttoken');
const tokenHeaders = { headers: { requesttoken: requestToken } };
@ -63,35 +64,7 @@ export default {
* @returns {Promise}
*/
requireAdmin() {
return new Promise(function(resolve, reject) {
// TODO: migrate the OC.dialog to Vue and avoid this mess
// wait for password confirmation
let passwordTimeout;
let waitForpassword = function() {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
passwordTimeout = setTimeout(waitForpassword, 500);
return;
}
clearTimeout(passwordTimeout);
clearTimeout(promiseTimeout);
resolve();
};
// automatically reject after 5s if not resolved
let promiseTimeout = setTimeout(() => {
clearTimeout(passwordTimeout);
// close dialog
if (document.getElementsByClassName('oc-dialog-close').length>0) {
document.getElementsByClassName('oc-dialog-close')[0].click();
}
OC.Notification.showTemporary(t('settings', 'You did not enter the password in time'));
reject('Password request cancelled');
}, 7000);
// request password
OC.PasswordConfirmation.requirePasswordConfirmation();
waitForpassword();
});
return confirmPassword();
},
get(url) {
return axios.get(sanitize(url), tokenHeaders)
@ -118,4 +91,4 @@ export default {
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
}
};
}