diff --git a/lib/plugins/authpdo/_test/sqlite.test.php b/lib/plugins/authpdo/_test/sqlite.test.php index 1d9058a682b5eea8a34cb8d844eb5cd0ab1f7d2b..aa8a4c25bf50cb4b7c5f9c7e7ea36332598b2eda 100644 --- a/lib/plugins/authpdo/_test/sqlite.test.php +++ b/lib/plugins/authpdo/_test/sqlite.test.php @@ -44,7 +44,9 @@ class sqlite_plugin_authpdo_test extends DokuWikiTest { $conf['plugin']['authpdo']['select-user'] = 'SELECT id AS uid, login AS user, name, pass AS clear, mail FROM user WHERE login = :user'; $conf['plugin']['authpdo']['select-user-groups'] = 'SELECT * FROM member AS m, "group" AS g WHERE m.gid = g.id AND m.uid = :uid'; $conf['plugin']['authpdo']['select-groups'] = 'SELECT id AS gid, "group" FROM "group"'; + $conf['plugin']['authpdo']['insert-user'] = 'INSERT INTO user (login, pass, name, mail) VALUES (:user, :hash, :name, :mail)'; + $conf['plugin']['authpdo']['delete-user'] = 'DELETE FROM user WHERE id = :uid'; $conf['plugin']['authpdo']['update-user-login'] = 'UPDATE user SET login = :newlogin WHERE id = :uid'; $conf['plugin']['authpdo']['update-user-info'] = 'UPDATE user SET name = :name, mail = :mail WHERE id = :uid'; @@ -122,6 +124,10 @@ class sqlite_plugin_authpdo_test extends DokuWikiTest { $auth->modifyUser('tester', array('grps' => array('user', 'admin', 'another'))); $info = $auth->getUserData('tester'); $this->assertEquals(array('admin', 'another', 'user'), $info['grps']); + + // delete user + $num = $auth->deleteUsers(array('tester', 'foobar')); + $this->assertEquals(1, $num); } } diff --git a/lib/plugins/authpdo/auth.php b/lib/plugins/authpdo/auth.php index 020b44546e950d2ddd792b51ffec3e5e03da7790..7833083b9c23fcf360669f79b9027b2e5bf0db1b 100644 --- a/lib/plugins/authpdo/auth.php +++ b/lib/plugins/authpdo/auth.php @@ -65,6 +65,7 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { // FIXME intialize your auth system and set success to true, if successful $this->success = true; + } /** @@ -276,17 +277,20 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { } /** - * Delete one or more users [implement only where required/possible] + * Delete one or more users * * Set delUser capability when implemented * * @param array $users * @return int number of users deleted */ - //public function deleteUsers($users) { - // FIXME implement - // return false; - //} + public function deleteUsers($users) { + $count = 0; + foreach($users as $user) { + if($this->_deleteUser($user)) $count++; + } + return $count; + } /** * Bulk retrieval of user data [implement only where required/possible] @@ -391,6 +395,35 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { return $data; } + /** + * Delete a user after removing all their group memberships + * + * @param string $user + * @return bool true when the user was deleted + */ + protected function _deleteUser($user) { + $this->pdo->beginTransaction(); + { + $userdata = $this->getUserData($user); + if($userdata === false) goto FAIL; + $allgroups = $this->_selectGroups(); + + // remove group memberships (ignore errors) + foreach($userdata['grps'] as $group) { + $this->_leaveGroup($userdata, $allgroups[$group]); + } + + $ok = $this->_query($this->getConf('delete-user'), $userdata); + if($ok === false) goto FAIL; + } + $this->pdo->commit(); + return true; + + FAIL: + $this->pdo->rollBack(); + return false; + } + /** * Select all groups of a user * diff --git a/lib/plugins/authpdo/conf/default.php b/lib/plugins/authpdo/conf/default.php index fd91456f5359eacff5985905a8dce76af5d5099b..762c3aeb523bf6458c2480eb8f2732a8069181f0 100644 --- a/lib/plugins/authpdo/conf/default.php +++ b/lib/plugins/authpdo/conf/default.php @@ -33,6 +33,13 @@ $conf['select-group'] = ''; */ $conf['insert-user'] = ''; +/** + * Remove a user + * + * input: :user, [:uid], [*] + */ +$conf['delete-user'] = ''; + /** * Update user data (except password and user name) *