From 8d33d76ce8f8102f64d6b615dfc178b31e397e62 Mon Sep 17 00:00:00 2001
From: Joas Schilling <coding@schilljs.com>
Date: Thu, 17 Nov 2016 10:36:39 +0100
Subject: [PATCH] Use the existing prompt

Signed-off-by: Joas Schilling <coding@schilljs.com>
---
 core/css/jquery.ocdialog.css |  1 -
 core/css/styles.css          | 35 --------------------
 core/js/js.js                | 64 +++++++++++++++---------------------
 3 files changed, 27 insertions(+), 73 deletions(-)

diff --git a/core/css/jquery.ocdialog.css b/core/css/jquery.ocdialog.css
index 0e46ff20152..d1a42694589 100644
--- a/core/css/jquery.ocdialog.css
+++ b/core/css/jquery.ocdialog.css
@@ -22,7 +22,6 @@
 .oc-dialog-buttonrow {
 	display: block;
 	background: transparent;
-	position: absolute;
 	right: 0;
 	bottom: 0;
 	padding: 10px;
diff --git a/core/css/styles.css b/core/css/styles.css
index 6e0156d2238..f0c4c4f33ff 100644
--- a/core/css/styles.css
+++ b/core/css/styles.css
@@ -983,38 +983,3 @@ fieldset.warning legend + p, fieldset.update legend + p {
    opacity: 0;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
 }
-
-#sudo-login-background {
-	position: absolute;
-	width: 100%;
-	height: 100%;
-	background-color: #1d2d44;
-	opacity:0.4;
-	z-index: 999;
-}
-
-#sudo-login-form {
-	position: absolute;
-	top: 45%;
-	left: 40%;
-	border: 1px solid #e9322d;
-	color: #e9322d;
-	font-weight: bold;
-	z-index: 1000;
-	background: #e4b9c0;
-	border-radius: 10px;
-	opacity:1;
-	padding: 25px;
-}
-
-#sudo-login-form .question {
-	width: 250px;
-}
-
-#sudo-login-form .confirm {
-	position: relative;
-	right: 32px;
-	border: none;
-	opacity: .3;
-	background-color: transparent;
-}
diff --git a/core/js/js.js b/core/js/js.js
index 4579fe394af..64c7dda31e2 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -1517,31 +1517,15 @@ function initCore() {
 }
 
 OC.PasswordConfirmation = {
-	$form: null,
-	$background: null,
-	$input: null,
-	$submit: null,
 	callback: null,
 
 	init: function() {
-		var self = this;
-		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));
-		this.$input.keyup(function(e) {
-			if (e.keyCode === 13) {
-				self._submitPasswordConfirmation();
-			}
-		});
 	},
 
 	requiresPasswordConfirmation: function() {
 		var timeSinceLogin = moment.now() - nc_lastLogin * 1000;
+		return timeSinceLogin > 10 * 1000; // 30 minutes
 		return timeSinceLogin > 30 * 60 * 1000; // 30 minutes
 	},
 
@@ -1549,50 +1533,56 @@ OC.PasswordConfirmation = {
 	 * @param {function} callback
 	 */
 	requirePasswordConfirmation: function(callback) {
+		var self = this;
+
 		if (this.requiresPasswordConfirmation()) {
-			this.$form.removeClass('hidden');
-			this.$background.removeClass('hidden');
-			this.$input.val('');
+			OC.dialogs.prompt(
+				t(
+					'core',
+					'This action requires you to confirm your password'
+				),
+				t('core','Authentication required'),
+				function (result, password) {
+					if (result && password !== '') {
+						self._confirmPassword(password);
+					}
+				},
+				true,
+				t('core','Password'),
+				true
+			).then(function() {
+				var $dialog = $('.oc-dialog:visible');
+				$dialog.find('.ui-icon').remove();
+
+				var $buttons = $dialog.find('button');
+				$buttons.eq(0).text(t('core', 'Cancel'));
+				$buttons.eq(1).text(t('core', 'Confirm'));
+			});
 		}
 
 		this.callback = callback;
 	},
 
-	_submitPasswordConfirmation: function() {
+	_confirmPassword: function(password) {
 		var self = this;
 
-		self.$submit.removeClass('icon-confirm').addClass('icon-loading-small');
-
 		$.ajax({
 			url: OC.generateUrl('/login/confirm'),
 			data: {
-				password: this.$input.val()
+				password: password
 			},
 			type: 'POST',
 			success: function(response) {
-				self.$input.val('');
 				nc_lastLogin = response.lastLogin;
-				self.$submit.addClass('icon-confirm').removeClass('icon-loading-small');
-
-				self.$form.addClass('hidden');
-				self.$background.addClass('hidden');
 
 				if (_.isFunction(self.callback)) {
 					self.callback();
 				}
 			},
 			error: function() {
-				self.$input.val('');
 				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 = '';
 	}
 };
 
-- 
GitLab