From de5467811a52abcc16d0b536136e09f1b614d79c Mon Sep 17 00:00:00 2001 From: Abijeet Date: Thu, 28 Dec 2017 01:41:16 +0530 Subject: [PATCH] Fixes password input being prompted every time. Fixes #7106 - Echoing the current server time via a JS variable and storing the current time on page load in JS. - Calculating the diff and taking it into account when deciding whether to show the password confirmation. Signed-off-by: Abijeet --- core/js/js.js | 7 +++++-- lib/private/Template/JSConfigHelper.php | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/js/js.js b/core/js/js.js index f9a5f2b338..872761c02b 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1675,13 +1675,16 @@ function initCore() { OC.PasswordConfirmation = { callback: null, - + pageLoadTime: null, init: function() { $('.password-confirm-required').on('click', _.bind(this.requirePasswordConfirmation, this)); + this.pageLoadTime = moment.now(); }, requiresPasswordConfirmation: function() { - var timeSinceLogin = moment.now() - (nc_lastLogin * 1000); + var serverTimeDiff = this.pageLoadTime - (nc_pageLoad * 1000); + var timeSinceLogin = moment.now() - (serverTimeDiff + (nc_lastLogin * 1000)); + // if timeSinceLogin > 30 minutes and user backend allows password confirmation return (backendAllowsPasswordConfirmation && timeSinceLogin > 30 * 60 * 1000); }, diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php index bdb747e1c9..9f93ef784b 100644 --- a/lib/private/Template/JSConfigHelper.php +++ b/lib/private/Template/JSConfigHelper.php @@ -155,6 +155,7 @@ class JSConfigHelper { "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), 'nc_lastLogin' => $lastConfirmTimestamp, + 'nc_pageLoad' => time(), "dayNames" => json_encode([ (string)$this->l->t('Sunday'), (string)$this->l->t('Monday'),