diff options
author | julia.kirschenheuter <julia.kirschenheuter@nextcloud.com> | 2023-10-04 16:31:28 +0200 |
---|---|---|
committer | julia.kirschenheuter <julia.kirschenheuter@nextcloud.com> | 2023-10-17 14:09:43 +0200 |
commit | 7d00c7fde48835e46f73400af29e88985829f759 (patch) | |
tree | 2f3f19398ef495a624cbd82ac6a3f5c87d46c525 /core | |
parent | 106bf6cf878869e8f3e6f5b2ec4034699d19d76d (diff) | |
download | nextcloud-server-7d00c7fde48835e46f73400af29e88985829f759.tar.gz nextcloud-server-7d00c7fde48835e46f73400af29e88985829f759.zip |
Replace password dialog with dialog from library
Signed-off-by: julia.kirschenheuter <julia.kirschenheuter@nextcloud.com>
Diffstat (limited to 'core')
-rw-r--r-- | core/js/tests/specs/coreSpec.js | 61 | ||||
-rw-r--r-- | core/src/OC/index.js | 3 | ||||
-rw-r--r-- | core/src/OC/password-confirmation.js | 96 | ||||
-rw-r--r-- | core/src/init.js | 2 |
4 files changed, 8 insertions, 154 deletions
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index 93d282c5d5e..b7339ce7188 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -1295,65 +1295,4 @@ describe('Core base tests', function() { expect(snapperStub.close.calledTwice).toBe(true); }); }); - describe('Requires password confirmation', function () { - var stubMomentNow; - var stubJsPageLoadTime; - - afterEach(function () { - delete window.nc_pageLoad; - delete window.nc_lastLogin; - delete window.backendAllowsPasswordConfirmation; - - stubMomentNow.restore(); - stubJsPageLoadTime.restore(); - }); - - it('should not show the password confirmation dialog when server time is earlier than local time', function () { - // add server variables - window.nc_pageLoad = parseInt(new Date(2018, 0, 3, 1, 15, 0).getTime() / 1000); - window.nc_lastLogin = parseInt(new Date(2018, 0, 3, 1, 0, 0).getTime() / 1000); - window.backendAllowsPasswordConfirmation = true; - - stubJsPageLoadTime = sinon.stub(OC.PasswordConfirmation, 'pageLoadTime').value(new Date(2018, 0, 3, 12, 15, 0).getTime()); - stubMomentNow = sinon.stub(moment, 'now').returns(new Date(2018, 0, 3, 12, 20, 0).getTime()); - - expect(OC.PasswordConfirmation.requiresPasswordConfirmation()).toBeFalsy(); - }); - - it('should show the password confirmation dialog when server time is earlier than local time', function () { - // add server variables - window.nc_pageLoad = parseInt(new Date(2018, 0, 3, 1, 15, 0).getTime() / 1000); - window.nc_lastLogin = parseInt(new Date(2018, 0, 3, 1, 0, 0).getTime() / 1000); - window.backendAllowsPasswordConfirmation = true; - - stubJsPageLoadTime = sinon.stub(OC.PasswordConfirmation, 'pageLoadTime').value(new Date(2018, 0, 3, 12, 15, 0).getTime()); - stubMomentNow = sinon.stub(moment, 'now').returns(new Date(2018, 0, 3, 12, 31, 0).getTime()); - - expect(OC.PasswordConfirmation.requiresPasswordConfirmation()).toBeTruthy(); - }); - - it('should not show the password confirmation dialog when server time is later than local time', function () { - // add server variables - window.nc_pageLoad = parseInt(new Date(2018, 0, 3, 23, 15, 0).getTime() / 1000); - window.nc_lastLogin = parseInt(new Date(2018, 0, 3, 23, 0, 0).getTime() / 1000); - window.backendAllowsPasswordConfirmation = true; - - stubJsPageLoadTime = sinon.stub(OC.PasswordConfirmation, 'pageLoadTime').value(new Date(2018, 0, 3, 12, 15, 0).getTime()); - stubMomentNow = sinon.stub(moment, 'now').returns(new Date(2018, 0, 3, 12, 20, 0).getTime()); - - expect(OC.PasswordConfirmation.requiresPasswordConfirmation()).toBeFalsy(); - }); - - it('should show the password confirmation dialog when server time is later than local time', function () { - // add server variables - window.nc_pageLoad = parseInt(new Date(2018, 0, 3, 23, 15, 0).getTime() / 1000); - window.nc_lastLogin = parseInt(new Date(2018, 0, 3, 23, 0, 0).getTime() / 1000); - window.backendAllowsPasswordConfirmation = true; - - stubJsPageLoadTime = sinon.stub(OC.PasswordConfirmation, 'pageLoadTime').value(new Date(2018, 0, 3, 12, 15, 0).getTime()); - stubMomentNow = sinon.stub(moment, 'now').returns(new Date(2018, 0, 3, 12, 31, 0).getTime()); - - expect(OC.PasswordConfirmation.requiresPasswordConfirmation()).toBeTruthy(); - }); - }); }); diff --git a/core/src/OC/index.js b/core/src/OC/index.js index 07064fba98e..33dd45a17ee 100644 --- a/core/src/OC/index.js +++ b/core/src/OC/index.js @@ -239,6 +239,9 @@ export default { msg, Notification, + /** + * @deprecated 28.0.0 use methods from '@nextcloud/password-confirmation' + */ PasswordConfirmation, Plugins, theme, diff --git a/core/src/OC/password-confirmation.js b/core/src/OC/password-confirmation.js index b67a6f4a1d3..210d6b1e5c1 100644 --- a/core/src/OC/password-confirmation.js +++ b/core/src/OC/password-confirmation.js @@ -22,110 +22,24 @@ * */ -import _ from 'underscore' -import $ from 'jquery' -import moment from 'moment' -import { generateUrl } from '@nextcloud/router' - -import OC from './index.js' +import { confirmPassword, isPasswordConfirmationRequired } from '@nextcloud/password-confirmation' +import '@nextcloud/password-confirmation/dist/style.css' /** * @namespace OC.PasswordConfirmation */ export default { - callback: null, - - pageLoadTime: null, - - init() { - $('.password-confirm-required').on('click', _.bind(this.requirePasswordConfirmation, this)) - this.pageLoadTime = moment.now() - }, requiresPasswordConfirmation() { - const serverTimeDiff = this.pageLoadTime - (window.nc_pageLoad * 1000) - const timeSinceLogin = moment.now() - (serverTimeDiff + (window.nc_lastLogin * 1000)) - - // if timeSinceLogin > 30 minutes and user backend allows password confirmation - return (window.backendAllowsPasswordConfirmation && timeSinceLogin > 30 * 60 * 1000) + return isPasswordConfirmationRequired() }, /** * @param {Function} callback success callback function - * @param {object} options options + * @param {object} options options currently not used by confirmPassword * @param {Function} rejectCallback error callback function */ requirePasswordConfirmation(callback, options, rejectCallback) { - options = typeof options !== 'undefined' ? options : {} - const defaults = { - title: t('core', 'Authentication required'), - text: t( - 'core', - 'This action requires you to confirm your password' - ), - confirm: t('core', 'Confirm'), - label: t('core', 'Password'), - error: '', - } - - const config = _.extend(defaults, options) - - const self = this - - if (this.requiresPasswordConfirmation()) { - OC.dialogs.prompt( - config.text, - config.title, - function(result, password) { - if (result && password !== '') { - self._confirmPassword(password, config) - } else if (_.isFunction(rejectCallback)) { - rejectCallback() - } - }, - true, - config.label, - true - ).then(function() { - const $dialog = $('.oc-dialog:visible') - $dialog.find('.ui-icon').remove() - $dialog.addClass('password-confirmation') - if (config.error !== '') { - const $error = $('<p></p>').addClass('msg warning').text(config.error) - $dialog.find('.oc-dialog-content').append($error) - } - const $buttonrow = $dialog.find('.oc-dialog-buttonrow') - $buttonrow.addClass('aside') - - const $buttons = $buttonrow.find('button') - $buttons.eq(0).hide() - $buttons.eq(1).text(config.confirm) - }) - } - - this.callback = callback - }, - - _confirmPassword(password, config) { - const self = this - - $.ajax({ - url: generateUrl('/login/confirm'), - data: { - password, - }, - type: 'POST', - success(response) { - window.nc_lastLogin = response.lastLogin - - if (_.isFunction(self.callback)) { - self.callback() - } - }, - error() { - config.error = t('core', 'Failed to authenticate, try again') - OC.PasswordConfirmation.requirePasswordConfirmation(self.callback, config) - }, - }) + confirmPassword().then(callback, rejectCallback) }, } diff --git a/core/src/init.js b/core/src/init.js index 5c72f087630..6114c612705 100644 --- a/core/src/init.js +++ b/core/src/init.js @@ -34,7 +34,6 @@ import OC from './OC/index.js' import { setUp as setUpContactsMenu } from './components/ContactsMenu.js' import { setUp as setUpMainMenu } from './components/MainMenu.js' import { setUp as setUpUserMenu } from './components/UserMenu.js' -import PasswordConfirmation from './OC/password-confirmation.js' import { interceptRequests } from './utils/xhr-request.js' // keep in sync with core/css/variables.scss @@ -298,5 +297,4 @@ export const initCore = () => { } initLiveTimestamps() - PasswordConfirmation.init() } |