diff options
Diffstat (limited to 'apps/files_encryption')
-rw-r--r-- | apps/files_encryption/ajax/getMigrationStatus.php | 27 | ||||
-rw-r--r-- | apps/files_encryption/appinfo/app.php | 3 | ||||
-rw-r--r-- | apps/files_encryption/js/detect-migration.js | 29 | ||||
-rw-r--r-- | apps/files_encryption/lib/util.php | 32 |
4 files changed, 75 insertions, 16 deletions
diff --git a/apps/files_encryption/ajax/getMigrationStatus.php b/apps/files_encryption/ajax/getMigrationStatus.php new file mode 100644 index 00000000000..4da035a97d4 --- /dev/null +++ b/apps/files_encryption/ajax/getMigrationStatus.php @@ -0,0 +1,27 @@ +<?php +/** + * Copyright (c) 2013, Bjoern Schiessle <schiessle@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($_POST['user']) ? $_POST['user'] : ''; +$password = isset($_POST['password']) ? $_POST['password'] : ''; + +$migrationCompleted = true; + +if ($user !== '' && $password !== '') { + if (\OCP\User::checkPassword($user, $password)) { + $util = new Util(new \OC_FilesystemView('/'), $user); + if ($util->getMigrationStatus() !== 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 c930ac9eca8..fd9aa429b01 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 00000000000..301e77f24f7 --- /dev/null +++ b/apps/files_encryption/js/detect-migration.js @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2013 + * Bjoern Schiessle <schiessle@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() { + var user = $('#user').val(); + var password = $('#password').val(); + $.ajax({ + type: 'POST', + 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.'); + $('#messageText').text(message); + $('#message').removeClass('hidden').addClass('update'); + } + } + }); + }); + +}); diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 33ab3f56965..434ed225644 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -1245,7 +1245,6 @@ class Util { $sql = 'SELECT `migration_status` FROM `*PREFIX*encryption` WHERE `uid` = ?'; $args = array($this->userId); - $query = \OCP\DB::prepare($sql); $result = $query->execute($args); @@ -1266,20 +1265,23 @@ 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); - // insert missing entry in DB with status open - $sql = 'INSERT INTO `*PREFIX*encryption` (`uid`,`mode`,`recovery_enabled`,`migration_status`) VALUES (?,?,?,?)'; - $args = array( - $this->userId, - 'server-side', - 0, - self::MIGRATION_OPEN - ); - $query = \OCP\DB::prepare($sql); - $query->execute($args); - - return self::MIGRATION_OPEN; - // If a record is found - } else { + // insert missing entry in DB with status open if the user exists + if (\OCP\User::userExists($this->userId)) { + $sql = 'INSERT INTO `*PREFIX*encryption` (`uid`,`mode`,`recovery_enabled`,`migration_status`) VALUES (?,?,?,?)'; + $args = array( + $this->userId, + 'server-side', + 0, + self::MIGRATION_OPEN + ); + $query = \OCP\DB::prepare($sql); + $query->execute($args); + + return self::MIGRATION_OPEN; + } else { + return false; + } + } else { // If a record is found return (int)$migrationStatus[0]; } |