diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-11-12 11:54:56 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-11-12 11:59:38 +0100 |
commit | 1cb5f316ed2113b1a546bb9a3daea1d5fe207785 (patch) | |
tree | 18979356ef7ec14e1d844b10147c043e35b73f62 | |
parent | d6de8ebeb272d677a4bf1930c6eb42c1bf57b844 (diff) | |
download | nextcloud-server-1cb5f316ed2113b1a546bb9a3daea1d5fe207785.tar.gz nextcloud-server-1cb5f316ed2113b1a546bb9a3daea1d5fe207785.zip |
Use nextcloud-password-confirmation
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
-rw-r--r-- | core/js/js.js | 6 | ||||
-rw-r--r-- | settings/package.json | 1 | ||||
-rw-r--r-- | settings/src/store/api.js | 33 |
3 files changed, 9 insertions, 31 deletions
diff --git a/core/js/js.js b/core/js/js.js index 026cc6bb0d6..361d2ab9b7e 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -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, diff --git a/settings/package.json b/settings/package.json index 932c26819f5..53692fcdc72 100644 --- a/settings/package.json +++ b/settings/package.json @@ -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", diff --git a/settings/src/store/api.js b/settings/src/store/api.js index 5bab785d94b..185e80253a3 100644 --- a/settings/src/store/api.js +++ b/settings/src/store/api.js @@ -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)); |