added post_createUser hook

This commit is contained in:
Florin Peter 2013-05-13 22:34:11 +02:00
parent 61ed347d26
commit b2d021b2a5
2 changed files with 38 additions and 12 deletions

View File

@ -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
*/

View File

@ -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;
}
}