[Pkg-owncloud-commits] [owncloud] 139/239: show a message at the log-in screen if inital encryption take place

David Prévot taffit at moszumanska.debian.org
Fri Nov 29 01:32:30 UTC 2013


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit d6fb2afa8580b7d12b1f0cfc2bb8fb29e01a087f
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Mon Nov 25 23:49:05 2013 +0100

    show a message at the log-in screen if inital encryption take place
---
 apps/files_encryption/ajax/getMigrationStatus.php | 28 ++++++++++++++++++++++
 apps/files_encryption/appinfo/app.php             |  3 ++-
 apps/files_encryption/js/detect-migration.js      | 29 +++++++++++++++++++++++
 apps/files_encryption/lib/util.php                | 16 +++++++++----
 core/templates/login.php                          |  4 +++-
 5 files changed, 73 insertions(+), 7 deletions(-)

diff --git a/apps/files_encryption/ajax/getMigrationStatus.php b/apps/files_encryption/ajax/getMigrationStatus.php
new file mode 100644
index 0000000..e6d2f3d
--- /dev/null
+++ b/apps/files_encryption/ajax/getMigrationStatus.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Copyright (c) 2013, Bjoern Schiessle <schiessle at owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ *
+ * @brief check migration status
+ */
+use OCA\Encryption\Util;
+
+\OCP\JSON::checkAppEnabled('files_encryption');
+
+$user = isset($_GET['user']) ? $_GET['user'] : '';
+$password = isset($_GET['password']) ? $_GET['password'] : '';
+
+$migrationCompleted = true;
+
+if ($user !== '' && $password !== '') {
+	if (\OCP\User::checkPassword($user, $password)) {
+		error_log("password ok");
+		$util = new Util(new \OC_FilesystemView('/'), $user);
+		if ($util->getMigrationStatus($user) !== Util::MIGRATION_COMPLETED) {
+			$migrationCompleted = false;
+		}
+	}
+}
+
+\OCP\JSON::success(array('data' => array('migrationCompleted' => $migrationCompleted)));
diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php
index c930ac9e..fd9aa42 100644
--- a/apps/files_encryption/appinfo/app.php
+++ b/apps/files_encryption/appinfo/app.php
@@ -10,6 +10,8 @@ OC::$CLASSPATH['OCA\Encryption\Session'] = 'files_encryption/lib/session.php';
 OC::$CLASSPATH['OCA\Encryption\Capabilities'] = 'files_encryption/lib/capabilities.php';
 OC::$CLASSPATH['OCA\Encryption\Helper'] = 'files_encryption/lib/helper.php';
 
+\OCP\Util::addscript('files_encryption', 'detect-migration');
+
 if (!OC_Config::getValue('maintenance', false)) {
 	OC_FileProxy::register(new OCA\Encryption\Proxy());
 
@@ -52,4 +54,3 @@ if (!OC_Config::getValue('maintenance', false)) {
 // Register settings scripts
 OCP\App::registerAdmin('files_encryption', 'settings-admin');
 OCP\App::registerPersonal('files_encryption', 'settings-personal');
-
diff --git a/apps/files_encryption/js/detect-migration.js b/apps/files_encryption/js/detect-migration.js
new file mode 100644
index 0000000..eadcd23
--- /dev/null
+++ b/apps/files_encryption/js/detect-migration.js
@@ -0,0 +1,29 @@
+/**
+ * Copyright (c) 2013
+ *  Bjoern Schiessle <schiessle at owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ */
+
+
+$(document).ready(function(){
+	$('form[name="login"]').on('submit', function(ev) {
+		var user = $('#user').val();
+		var password = $('#password').val();
+		$.ajax({
+			type: 'GET',
+			url: OC.linkTo('files_encryption', 'ajax/getMigrationStatus.php'),
+			dataType: 'json',
+			data: {user: user, password: password},
+			async: false,
+			success: function(response) {
+				if (response.data.migrationCompleted === false) {
+					var message = t('files_encryption', 'Initial encryption started... This can take some time. Please wait.');
+					$('p[name="message"]').html('<img src="' + OC.imagePath('core', 'loading-small.gif') + '"/>  ' + message);
+					$('p[name="message"]').removeClass('hidden').addClass('info');
+				}
+			}
+		});
+	});
+
+});
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index b208a80..78d0ff8 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -1253,16 +1253,22 @@ class Util {
 
 	/**
 	 * @brief check if files are already migrated to the encryption system
+	 * @param string $uid user Id
 	 * @return migration status, false = in case of no record
 	 * @note If records are not being returned, check for a hidden space
 	 *       at the start of the uid in db
 	 */
-	public function getMigrationStatus() {
+	public function getMigrationStatus($uid = null) {
 
-		$sql = 'SELECT `migration_status` FROM `*PREFIX*encryption` WHERE `uid` = ?';
+		if($uid && \OCP\User::userExists($uid)) {
+			$userId = $uid;
+		} else {
+			$userId = $this->uid;
+		}
 
-		$args = array($this->userId);
+		$sql = 'SELECT `migration_status` FROM `*PREFIX*encryption` WHERE `uid` = ?';
 
+		$args = array($userId);
 		$query = \OCP\DB::prepare($sql);
 
 		$result = $query->execute($args);
@@ -1282,11 +1288,11 @@ class Util {
 
 		// If no record is found
 		if (empty($migrationStatus)) {
-			\OCP\Util::writeLog('Encryption library', "Could not get migration status for " . $this->userId . ", no record found", \OCP\Util::ERROR);
+			\OCP\Util::writeLog('Encryption library', "Could not get migration status for " . $userId . ", no record found", \OCP\Util::ERROR);
 			// insert missing entry in DB with status open
 			$sql = 'INSERT INTO `*PREFIX*encryption` (`uid`,`mode`,`recovery_enabled`,`migration_status`) VALUES (?,?,?,?)';
 			$args = array(
-				$this->userId,
+				$userId,
 				'server-side',
 				0,
 				self::MIGRATION_OPEN
diff --git a/core/templates/login.php b/core/templates/login.php
index aca42c8..214fda3 100644
--- a/core/templates/login.php
+++ b/core/templates/login.php
@@ -1,5 +1,5 @@
 <!--[if IE 8]><style>input[type="checkbox"]{padding:0;}</style><![endif]-->
-<form method="post">
+<form method="post" name="login">
 	<fieldset>
 	<?php if (!empty($_['redirect_url'])) {
 		print_unescaped('<input type="hidden" name="redirect_url" value="' . OC_Util::sanitizeHTML($_['redirect_url']) . '" />');
@@ -18,6 +18,8 @@
 				<small><?php p($l->t('Please contact your administrator.')); ?></small>
 			</div>
 		<?php endif; ?>
+		<p name="message" class="hidden">
+		</p>
 		<p class="infield grouptop">
 			<input type="text" name="user" id="user" placeholder=""
 				   value="<?php p($_['username']); ?>"<?php p($_['user_autofocus'] ? ' autofocus' : ''); ?>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list