diff options
author | Joas Schilling <coding@schilljs.com> | 2016-09-19 15:33:30 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-11-18 11:57:16 +0100 |
commit | d75e35b75e9d70e511bee2c9fc830825363a4fd6 (patch) | |
tree | 0bfd1570211d1a8561c916d202b5f976a9d86445 /core/js/js.js | |
parent | 54ca411ff097d64d33c2d1e90102ef1fb1927f40 (diff) | |
download | nextcloud-server-d75e35b75e9d70e511bee2c9fc830825363a4fd6.tar.gz nextcloud-server-d75e35b75e9d70e511bee2c9fc830825363a4fd6.zip |
Introduce the UI for password confirmation
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'core/js/js.js')
-rw-r--r-- | core/js/js.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/core/js/js.js b/core/js/js.js index 54b103a7b7d..bc99e1c77da 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1512,8 +1512,72 @@ function initCore() { $(this).text(OC.Util.relativeModifiedDate(parseInt($(this).attr('data-timestamp'), 10))); }); }, 30 * 1000); + + OC.PasswordConfirmation.init(); } +OC.PasswordConfirmation = { + $form: null, + $background: null, + $input: null, + $submit: null, + + init: function() { + this.$form = $('#sudo-login-form'); + this.$background = $('#sudo-login-background'); + this.$input = this.$form.find('.question'); + this.$submit = this.$form.find('.confirm'); + + this.$background.on('click', _.bind(this._fadeOut, this)); + $('.password-confirm-required').on('click', _.bind(this.requirePasswordConfirmation, this)); + this.$submit.on('click', _.bind(this._submitPasswordConfirmation, this)); + }, + + requirePasswordConfirmation: function() { + var timeSinceLogin = moment.now() - nc_lastLogin * 1000; + if (timeSinceLogin > 30 * 60 * 1000) { // 30 minutes + this.$form.removeClass('hidden'); + this.$background.removeClass('hidden'); + + // Hack against firefox ignoring autocomplete="off" + if (this.$input.val() === ' ') { + this.$input.val(''); + } + } + }, + + _submitPasswordConfirmation: function() { + var self = this; + + self.$submit.removeClass('icon-confirm').addClass('icon-loading-small'); + + $.ajax({ + url: OC.generateUrl('/login/confirm'), + data: { + password: this.$input.val() + }, + type: 'POST', + success: function(response) { + nc_lastLogin = response.lastLogin; + self.$submit.addClass('icon-confirm').removeClass('icon-loading-small'); + + self.$form.addClass('hidden'); + self.$background.addClass('hidden'); + }, + error: function() { + OC.Notification.showTemporary(t('core', 'Failed to authenticate, try again')); + self.$submit.addClass('icon-confirm').removeClass('icon-loading-small'); + } + }); + }, + + _fadeOut: function() { + this.$form.addClass('hidden'); + this.$background.addClass('hidden'); + this.$input.value = ''; + } +}; + $(document).ready(initCore); /** |