mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Replace password dialog with dialog from library
Signed-off-by: julia.kirschenheuter <julia.kirschenheuter@nextcloud.com>
This commit is contained in:
parent
106bf6cf87
commit
7d00c7fde4
10 changed files with 17 additions and 163 deletions
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -239,6 +239,9 @@ export default {
|
|||
|
||||
msg,
|
||||
Notification,
|
||||
/**
|
||||
* @deprecated 28.0.0 use methods from '@nextcloud/password-confirmation'
|
||||
*/
|
||||
PasswordConfirmation,
|
||||
Plugins,
|
||||
theme,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
4
dist/core-common.js
vendored
4
dist/core-common.js
vendored
File diff suppressed because one or more lines are too long
2
dist/core-common.js.map
vendored
2
dist/core-common.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/core-login.js
vendored
4
dist/core-login.js
vendored
File diff suppressed because one or more lines are too long
2
dist/core-login.js.map
vendored
2
dist/core-login.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/core-main.js
vendored
4
dist/core-main.js
vendored
File diff suppressed because one or more lines are too long
2
dist/core-main.js.map
vendored
2
dist/core-main.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue