Use nextcloud-password-confirmation
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
d6de8ebeb2
commit
1cb5f316ed
3 changed files with 9 additions and 31 deletions
|
@ -1751,7 +1751,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'),
|
||||
|
@ -1775,6 +1775,10 @@ OC.PasswordConfirmation = {
|
|||
function (result, password) {
|
||||
if (result && password !== '') {
|
||||
self._confirmPassword(password, config);
|
||||
} else {
|
||||
if (rejectCallback && typeof rejectCallback === 'function') {
|
||||
rejectCallback()
|
||||
}
|
||||
}
|
||||
},
|
||||
true,
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"@babel/polyfill": "^7.0.0",
|
||||
"lodash": "^4.17.11",
|
||||
"nextcloud-axios": "^0.1.2",
|
||||
"nextcloud-password-confirmation": "^0.3.1",
|
||||
"nextcloud-vue": "^0.3.1",
|
||||
"v-tooltip": "^2.0.0-rc.33",
|
||||
"vue": "^2.5.17",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
|
||||
*
|
||||
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
||||
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
|
||||
import axios from 'nextcloud-axios'
|
||||
import confirmPassword from 'nextcloud-password-confirmation'
|
||||
|
||||
const sanitize = function(url) {
|
||||
return url.replace(/\/$/, ''); // Remove last url slash
|
||||
|
@ -60,35 +61,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));
|
||||
|
|
Loading…
Reference in a new issue