From b2d021b2a5a603505c6c0e607472ee4e91962afe Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Mon, 13 May 2013 22:34:11 +0200 Subject: [PATCH] added post_createUser hook --- apps/files_encryption/hooks/hooks.php | 30 ++++++++++++++++----------- apps/files_encryption/lib/helper.php | 20 ++++++++++++++++++ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 71a0fc9268..ebaa9c5145 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -47,17 +47,11 @@ class Hooks { $view = new \OC_FilesystemView( '/' ); $util = new Util( $view, $params['uid'] ); - - // Check files_encryption infrastructure is ready for action - if ( ! $util->ready() ) { - - \OC_Log::write( 'Encryption library', 'User account "' . $params['uid'] . '" is not ready for encryption; configuration started', \OC_Log::DEBUG ); - - if(!$util->setupServerSide( $params['password'] )) { - return false; - } - } + // setup user, if user not ready force relogin + if(Helper::setupUser($util, $params['password']) === false) { + return false; + } \OC_FileProxy::$enabled = false; @@ -120,8 +114,20 @@ class Hooks { return true; } - - /** + + /** + * @brief setup encryption backend upon user created + * @note This method should never be called for users using client side encryption + */ + public static function postCreateUser( $params ) { + $view = new \OC_FilesystemView( '/' ); + + $util = new Util( $view, $params['uid'] ); + + Helper::setupUser($util, $params['password']); + } + + /** * @brief Change a user's encryption passphrase * @param array $params keys: uid, password */ diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index 9b8d9ffc5b..3a5b2f78ce 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -48,6 +48,7 @@ class Helper { \OCP\Util::connectHook( 'OC_User', 'post_login', 'OCA\Encryption\Hooks', 'login' ); \OCP\Util::connectHook( 'OC_User', 'pre_setPassword', 'OCA\Encryption\Hooks', 'setPassphrase' ); + \OCP\Util::connectHook( 'OC_User', 'post_createUser', 'OCA\Encryption\Hooks', 'postCreateUser' ); } /** @@ -68,5 +69,24 @@ class Helper { \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Encryption\Hooks', 'postRename'); } + /** + * @brief setup user for files_encryption + * + * @param Util $util + * @param string $password + * @return bool + */ + public static function setupUser($util, $password) { + // Check files_encryption infrastructure is ready for action + if ( ! $util->ready() ) { + \OC_Log::write( 'Encryption library', 'User account "' . $util->getUserId() . '" is not ready for encryption; configuration started', \OC_Log::DEBUG ); + + if(!$util->setupServerSide( $password )) { + return false; + } + } + + return true; + } } \ No newline at end of file