From 226439a31c836a327ebd8b6a3171bcffa7250597 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 22 Mar 2018 08:59:10 +0100 Subject: [PATCH 1/9] Add interfaces for user backend functionality Signed-off-by: Roeland Jago Douma --- .../User/Backend/ICheckPasswordBackend.php | 29 +++++++++++++++++++ .../User/Backend/ICountUsersBackend.php | 29 +++++++++++++++++++ .../User/Backend/ICreateUserBackend.php | 29 +++++++++++++++++++ .../User/Backend/IGetDisplayNameBackend.php | 29 +++++++++++++++++++ lib/public/User/Backend/IGetHomeBackend.php | 29 +++++++++++++++++++ .../User/Backend/IProvideAvatarBackend.php | 29 +++++++++++++++++++ .../User/Backend/ISetDisplayNameBackend.php | 29 +++++++++++++++++++ .../User/Backend/ISetPasswordBackend.php | 29 +++++++++++++++++++ 8 files changed, 232 insertions(+) create mode 100644 lib/public/User/Backend/ICheckPasswordBackend.php create mode 100644 lib/public/User/Backend/ICountUsersBackend.php create mode 100644 lib/public/User/Backend/ICreateUserBackend.php create mode 100644 lib/public/User/Backend/IGetDisplayNameBackend.php create mode 100644 lib/public/User/Backend/IGetHomeBackend.php create mode 100644 lib/public/User/Backend/IProvideAvatarBackend.php create mode 100644 lib/public/User/Backend/ISetDisplayNameBackend.php create mode 100644 lib/public/User/Backend/ISetPasswordBackend.php diff --git a/lib/public/User/Backend/ICheckPasswordBackend.php b/lib/public/User/Backend/ICheckPasswordBackend.php new file mode 100644 index 0000000000..819a60bdc7 --- /dev/null +++ b/lib/public/User/Backend/ICheckPasswordBackend.php @@ -0,0 +1,29 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Backend; + +interface ICheckPasswordBackend { + public function checkPassword(string $loginName, string $password): string; +} diff --git a/lib/public/User/Backend/ICountUsersBackend.php b/lib/public/User/Backend/ICountUsersBackend.php new file mode 100644 index 0000000000..506eddffcc --- /dev/null +++ b/lib/public/User/Backend/ICountUsersBackend.php @@ -0,0 +1,29 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Backend; + +interface ICountUsersBackend { + public function countUsers(): int; +} diff --git a/lib/public/User/Backend/ICreateUserBackend.php b/lib/public/User/Backend/ICreateUserBackend.php new file mode 100644 index 0000000000..dec56d8808 --- /dev/null +++ b/lib/public/User/Backend/ICreateUserBackend.php @@ -0,0 +1,29 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Backend; + +interface ICreateUserBackend { + public function createUser(string $uid, string $password): bool; +} diff --git a/lib/public/User/Backend/IGetDisplayNameBackend.php b/lib/public/User/Backend/IGetDisplayNameBackend.php new file mode 100644 index 0000000000..71c1635fc3 --- /dev/null +++ b/lib/public/User/Backend/IGetDisplayNameBackend.php @@ -0,0 +1,29 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Backend; + +interface IGetDisplayNameBackend { + public function getDisplayName(string $uid): string; +} diff --git a/lib/public/User/Backend/IGetHomeBackend.php b/lib/public/User/Backend/IGetHomeBackend.php new file mode 100644 index 0000000000..a16c6eaba2 --- /dev/null +++ b/lib/public/User/Backend/IGetHomeBackend.php @@ -0,0 +1,29 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Backend; + +interface IGetHomeBackend { + public function getHome(string $uid): string; +} diff --git a/lib/public/User/Backend/IProvideAvatarBackend.php b/lib/public/User/Backend/IProvideAvatarBackend.php new file mode 100644 index 0000000000..fa37593251 --- /dev/null +++ b/lib/public/User/Backend/IProvideAvatarBackend.php @@ -0,0 +1,29 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Backend; + +interface IProvideAvatarBackend { + public function canChangeAvatar(string $uid): bool; +} diff --git a/lib/public/User/Backend/ISetDisplayNameBackend.php b/lib/public/User/Backend/ISetDisplayNameBackend.php new file mode 100644 index 0000000000..24b8316392 --- /dev/null +++ b/lib/public/User/Backend/ISetDisplayNameBackend.php @@ -0,0 +1,29 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Backend; + +interface ISetDisplayNameBackend { + public function setDisplayName(string $uid, string $displayName): bool; +} diff --git a/lib/public/User/Backend/ISetPasswordBackend.php b/lib/public/User/Backend/ISetPasswordBackend.php new file mode 100644 index 0000000000..42affcc245 --- /dev/null +++ b/lib/public/User/Backend/ISetPasswordBackend.php @@ -0,0 +1,29 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Backend; + +interface ISetPasswordBackend { + public function setPassword(string $uid, string $password): bool; +} From 355abbc96d39335677cc9d749ceae62955204dab Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 22 Mar 2018 09:15:19 +0100 Subject: [PATCH 2/9] Add abstract bakend to still be backwards compatible with the old logic Signed-off-by: Roeland Jago Douma --- lib/public/User/Backend/AbstractBackend.php | 62 +++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 lib/public/User/Backend/AbstractBackend.php diff --git a/lib/public/User/Backend/AbstractBackend.php b/lib/public/User/Backend/AbstractBackend.php new file mode 100644 index 0000000000..4ad3b15042 --- /dev/null +++ b/lib/public/User/Backend/AbstractBackend.php @@ -0,0 +1,62 @@ + +* +* @author Roeland Jago Douma +* +* @license GNU AGPL version 3 or any later version +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +*/ + +namespace OCP\User\Backend; + +use OC\User\Backend; +use OCP\IUserBackend; +use OCP\UserInterface; + +abstract class AbstractBackend implements IUserBackend, UserInterface { + public function implementsActions($actions): bool { + $implements = 0; + + if ($this instanceof ICreateUserBackend) { + $implements |= Backend::CREATE_USER; + } + if ($this instanceof ISetPasswordBackend) { + $implements |= Backend::SET_PASSWORD; + } + if ($this instanceof ICheckPasswordBackend) { + $implements |= Backend::CHECK_PASSWORD; + } + if ($this instanceof IGetHomeBackend) { + $implements |= Backend::GET_HOME; + } + if ($this instanceof IGetDisplayNameBackend) { + $implements |= Backend::GET_DISPLAYNAME; + } + if ($this instanceof ISetDisplayNameBackend) { + $implements |= Backend::SET_DISPLAYNAME; + } + if ($this instanceof IProvideAvatarBackend) { + $implements |= Backend::PROVIDE_AVATAR; + } + if ($this instanceof ICountUsersBackend) { + $implements |= Backend::COUNT_USERS; + } + + return (bool)($actions & $implements); + } +} From 140e7b609fb4d97e7ab3469ea4360de4c16af10c Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 22 Mar 2018 10:53:29 +0100 Subject: [PATCH 3/9] Fix phpdoc Signed-off-by: Roeland Jago Douma --- lib/public/User/Backend/AbstractBackend.php | 7 +++++++ lib/public/User/Backend/ICheckPasswordBackend.php | 6 ++++++ lib/public/User/Backend/ICountUsersBackend.php | 7 +++++++ lib/public/User/Backend/ICreateUserBackend.php | 7 +++++++ lib/public/User/Backend/IGetDisplayNameBackend.php | 7 +++++++ lib/public/User/Backend/IGetHomeBackend.php | 7 +++++++ lib/public/User/Backend/IProvideAvatarBackend.php | 7 +++++++ lib/public/User/Backend/ISetDisplayNameBackend.php | 7 +++++++ lib/public/User/Backend/ISetPasswordBackend.php | 7 +++++++ 9 files changed, 62 insertions(+) diff --git a/lib/public/User/Backend/AbstractBackend.php b/lib/public/User/Backend/AbstractBackend.php index 4ad3b15042..7fa7baf5cd 100644 --- a/lib/public/User/Backend/AbstractBackend.php +++ b/lib/public/User/Backend/AbstractBackend.php @@ -28,7 +28,14 @@ use OC\User\Backend; use OCP\IUserBackend; use OCP\UserInterface; +/** + * @since 14.0.0 + */ abstract class AbstractBackend implements IUserBackend, UserInterface { + + /** + * @deprecated 14.0.0 + */ public function implementsActions($actions): bool { $implements = 0; diff --git a/lib/public/User/Backend/ICheckPasswordBackend.php b/lib/public/User/Backend/ICheckPasswordBackend.php index 819a60bdc7..62a7f6e27c 100644 --- a/lib/public/User/Backend/ICheckPasswordBackend.php +++ b/lib/public/User/Backend/ICheckPasswordBackend.php @@ -24,6 +24,12 @@ declare(strict_types=1); namespace OCP\User\Backend; +/** + * @since 14.0.0 + */ interface ICheckPasswordBackend { + /** + * @since 14.0.0 + */ public function checkPassword(string $loginName, string $password): string; } diff --git a/lib/public/User/Backend/ICountUsersBackend.php b/lib/public/User/Backend/ICountUsersBackend.php index 506eddffcc..c7f6a102b7 100644 --- a/lib/public/User/Backend/ICountUsersBackend.php +++ b/lib/public/User/Backend/ICountUsersBackend.php @@ -24,6 +24,13 @@ declare(strict_types=1); namespace OCP\User\Backend; +/** + * @since 14.0.0 + */ interface ICountUsersBackend { + + /** + * @since 14.0.0 + */ public function countUsers(): int; } diff --git a/lib/public/User/Backend/ICreateUserBackend.php b/lib/public/User/Backend/ICreateUserBackend.php index dec56d8808..d3454c613c 100644 --- a/lib/public/User/Backend/ICreateUserBackend.php +++ b/lib/public/User/Backend/ICreateUserBackend.php @@ -24,6 +24,13 @@ declare(strict_types=1); namespace OCP\User\Backend; +/** + * @since 14.0.0 + */ interface ICreateUserBackend { + + /** + * @since 14.0.0 + */ public function createUser(string $uid, string $password): bool; } diff --git a/lib/public/User/Backend/IGetDisplayNameBackend.php b/lib/public/User/Backend/IGetDisplayNameBackend.php index 71c1635fc3..403f5afce5 100644 --- a/lib/public/User/Backend/IGetDisplayNameBackend.php +++ b/lib/public/User/Backend/IGetDisplayNameBackend.php @@ -24,6 +24,13 @@ declare(strict_types=1); namespace OCP\User\Backend; +/** + * @since 14.0.0 + */ interface IGetDisplayNameBackend { + + /** + * @since 14.0.0 + */ public function getDisplayName(string $uid): string; } diff --git a/lib/public/User/Backend/IGetHomeBackend.php b/lib/public/User/Backend/IGetHomeBackend.php index a16c6eaba2..3f19c1246a 100644 --- a/lib/public/User/Backend/IGetHomeBackend.php +++ b/lib/public/User/Backend/IGetHomeBackend.php @@ -24,6 +24,13 @@ declare(strict_types=1); namespace OCP\User\Backend; +/** + * @since 14.0.0 + */ interface IGetHomeBackend { + + /** + * @since 14.0.0 + */ public function getHome(string $uid): string; } diff --git a/lib/public/User/Backend/IProvideAvatarBackend.php b/lib/public/User/Backend/IProvideAvatarBackend.php index fa37593251..9aefda0e27 100644 --- a/lib/public/User/Backend/IProvideAvatarBackend.php +++ b/lib/public/User/Backend/IProvideAvatarBackend.php @@ -24,6 +24,13 @@ declare(strict_types=1); namespace OCP\User\Backend; +/** + * @since 14.0.0 + */ interface IProvideAvatarBackend { + + /** + * @since 14.0.0 + */ public function canChangeAvatar(string $uid): bool; } diff --git a/lib/public/User/Backend/ISetDisplayNameBackend.php b/lib/public/User/Backend/ISetDisplayNameBackend.php index 24b8316392..23f8478282 100644 --- a/lib/public/User/Backend/ISetDisplayNameBackend.php +++ b/lib/public/User/Backend/ISetDisplayNameBackend.php @@ -24,6 +24,13 @@ declare(strict_types=1); namespace OCP\User\Backend; +/** + * @since 14.0.0 + */ interface ISetDisplayNameBackend { + + /** + * @since 14.0.0 + */ public function setDisplayName(string $uid, string $displayName): bool; } diff --git a/lib/public/User/Backend/ISetPasswordBackend.php b/lib/public/User/Backend/ISetPasswordBackend.php index 42affcc245..ec008b33a5 100644 --- a/lib/public/User/Backend/ISetPasswordBackend.php +++ b/lib/public/User/Backend/ISetPasswordBackend.php @@ -24,6 +24,13 @@ declare(strict_types=1); namespace OCP\User\Backend; +/** + * @since 14.0.0 + */ interface ISetPasswordBackend { + + /** + * @since 14.0.0 + */ public function setPassword(string $uid, string $password): bool; } From c30b9dacae2d10f75562141479c02b8f941c4181 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 22 Mar 2018 09:16:34 +0100 Subject: [PATCH 4/9] Deprecate implementsActions Signed-off-by: Roeland Jago Douma --- lib/public/UserInterface.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/public/UserInterface.php b/lib/public/UserInterface.php index 61136783b3..b82fc6ba55 100644 --- a/lib/public/UserInterface.php +++ b/lib/public/UserInterface.php @@ -48,6 +48,7 @@ interface UserInterface { * Returns the supported actions as int to be * compared with \OC\User\Backend::CREATE_USER etc. * @since 4.5.0 + * @deprecated 14.0.0 Switch to the interfaces from OCP\User\Backend */ public function implementsActions($actions); From 5aa0d83268fc6781d50c38b869cbad31d65377eb Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 22 Mar 2018 12:18:54 +0100 Subject: [PATCH 5/9] Remove type declarations where not yet possible Because we don't return consistent things yet :( Signed-off-by: Roeland Jago Douma --- lib/public/User/Backend/ICheckPasswordBackend.php | 2 +- lib/public/User/Backend/ICountUsersBackend.php | 2 +- lib/public/User/Backend/IGetDisplayNameBackend.php | 2 +- lib/public/User/Backend/IGetHomeBackend.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/public/User/Backend/ICheckPasswordBackend.php b/lib/public/User/Backend/ICheckPasswordBackend.php index 62a7f6e27c..858c2d8c7d 100644 --- a/lib/public/User/Backend/ICheckPasswordBackend.php +++ b/lib/public/User/Backend/ICheckPasswordBackend.php @@ -31,5 +31,5 @@ interface ICheckPasswordBackend { /** * @since 14.0.0 */ - public function checkPassword(string $loginName, string $password): string; + public function checkPassword(string $loginName, string $password); } diff --git a/lib/public/User/Backend/ICountUsersBackend.php b/lib/public/User/Backend/ICountUsersBackend.php index c7f6a102b7..358557920d 100644 --- a/lib/public/User/Backend/ICountUsersBackend.php +++ b/lib/public/User/Backend/ICountUsersBackend.php @@ -32,5 +32,5 @@ interface ICountUsersBackend { /** * @since 14.0.0 */ - public function countUsers(): int; + public function countUsers(); } diff --git a/lib/public/User/Backend/IGetDisplayNameBackend.php b/lib/public/User/Backend/IGetDisplayNameBackend.php index 403f5afce5..f703e17157 100644 --- a/lib/public/User/Backend/IGetDisplayNameBackend.php +++ b/lib/public/User/Backend/IGetDisplayNameBackend.php @@ -32,5 +32,5 @@ interface IGetDisplayNameBackend { /** * @since 14.0.0 */ - public function getDisplayName(string $uid): string; + public function getDisplayName($uid): string; } diff --git a/lib/public/User/Backend/IGetHomeBackend.php b/lib/public/User/Backend/IGetHomeBackend.php index 3f19c1246a..607070932e 100644 --- a/lib/public/User/Backend/IGetHomeBackend.php +++ b/lib/public/User/Backend/IGetHomeBackend.php @@ -32,5 +32,5 @@ interface IGetHomeBackend { /** * @since 14.0.0 */ - public function getHome(string $uid): string; + public function getHome(string $uid); } From cbd2be583a4d728614fe09aef1bd3456210c6a1d Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 22 Mar 2018 12:19:26 +0100 Subject: [PATCH 6/9] Move Database backend over to new User/Backend interfaces Signed-off-by: Roeland Jago Douma --- lib/private/User/Database.php | 46 +++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php index 8dad3ef5fc..f4e9155bdb 100644 --- a/lib/private/User/Database.php +++ b/lib/private/User/Database.php @@ -1,4 +1,5 @@ userExists($uid)) { $event = new GenericEvent($password); $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); $query = \OC_DB::prepare('INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )'); try { - $result = $query->execute(array($uid, \OC::$server->getHasher()->hash($password))); + $result = $query->execute([$uid, \OC::$server->getHasher()->hash($password)]); } catch (\Exception $e) { $result = false; } @@ -124,7 +138,7 @@ class Database extends Backend implements IUserBackend { public function deleteUser($uid) { // Delete user-group-relation $query = \OC_DB::prepare('DELETE FROM `*PREFIX*users` WHERE `uid` = ?'); - $result = $query->execute(array($uid)); + $result = $query->execute([$uid]); if (isset($this->cache[$uid])) { unset($this->cache[$uid]); @@ -142,12 +156,12 @@ class Database extends Backend implements IUserBackend { * * Change the password of a user */ - public function setPassword($uid, $password) { + public function setPassword(string $uid, string $password): bool { if ($this->userExists($uid)) { $event = new GenericEvent($password); $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); $query = \OC_DB::prepare('UPDATE `*PREFIX*users` SET `password` = ? WHERE `uid` = ?'); - $result = $query->execute(array(\OC::$server->getHasher()->hash($password), $uid)); + $result = $query->execute([\OC::$server->getHasher()->hash($password), $uid]); return $result ? true : false; } @@ -164,10 +178,10 @@ class Database extends Backend implements IUserBackend { * * Change the display name of a user */ - public function setDisplayName($uid, $displayName) { + public function setDisplayName(string $uid, string $displayName): bool { if ($this->userExists($uid)) { $query = \OC_DB::prepare('UPDATE `*PREFIX*users` SET `displayname` = ? WHERE LOWER(`uid`) = LOWER(?)'); - $query->execute(array($displayName, $uid)); + $query->execute([$displayName, $uid]); $this->cache[$uid]['displayname'] = $displayName; return true; @@ -182,7 +196,7 @@ class Database extends Backend implements IUserBackend { * @param string $uid user ID of the user * @return string display name */ - public function getDisplayName($uid) { + public function getDisplayName($uid): string { $this->loadUser($uid); return empty($this->cache[$uid]['displayname']) ? $uid : $this->cache[$uid]['displayname']; } @@ -235,9 +249,9 @@ class Database extends Backend implements IUserBackend { * Check if the password is correct without logging in the user * returns the user id or false */ - public function checkPassword($uid, $password) { + public function checkPassword(string $uid, string $password) { $query = \OC_DB::prepare('SELECT `uid`, `password` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)'); - $result = $query->execute(array($uid)); + $result = $query->execute([$uid]); $row = $result->fetchRow(); if ($row) { @@ -271,7 +285,7 @@ class Database extends Backend implements IUserBackend { } $query = \OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)'); - $result = $query->execute(array($uid)); + $result = $query->execute([$uid]); if ($result === false) { Util::writeLog('core', \OC_DB::getErrorMessage(), Util::ERROR); @@ -326,9 +340,9 @@ class Database extends Backend implements IUserBackend { * @param string $uid the username * @return string|false */ - public function getHome($uid) { + public function getHome(string $uid) { if ($this->userExists($uid)) { - return \OC::$server->getConfig()->getSystemValue("datadirectory", \OC::$SERVERROOT . "/data") . '/' . $uid; + return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid; } return false; From 471272d456db574c82edcbb0eda2ac2deaa55059 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 22 Mar 2018 15:49:07 +0100 Subject: [PATCH 7/9] Move to ABackend Signed-off-by: Roeland Jago Douma --- lib/private/User/Database.php | 4 ++-- lib/public/User/Backend/{AbstractBackend.php => ABackend.php} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename lib/public/User/Backend/{AbstractBackend.php => ABackend.php} (96%) diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php index f4e9155bdb..d92390cdc9 100644 --- a/lib/private/User/Database.php +++ b/lib/private/User/Database.php @@ -58,7 +58,7 @@ declare(strict_types=1); namespace OC\User; use OC\Cache\CappedMemoryCache; -use OCP\User\Backend\AbstractBackend; +use OCP\User\Backend\ABackend; use OCP\User\Backend\ICheckPasswordBackend; use OCP\User\Backend\ICountUsersBackend; use OCP\User\Backend\ICreateUserBackend; @@ -73,7 +73,7 @@ use Symfony\Component\EventDispatcher\GenericEvent; /** * Class for user management in a SQL Database (e.g. MySQL, SQLite) */ -class Database extends AbstractBackend +class Database extends ABackend implements ICreateUserBackend, ISetPasswordBackend, ISetDisplayNameBackend, diff --git a/lib/public/User/Backend/AbstractBackend.php b/lib/public/User/Backend/ABackend.php similarity index 96% rename from lib/public/User/Backend/AbstractBackend.php rename to lib/public/User/Backend/ABackend.php index 7fa7baf5cd..48d410737d 100644 --- a/lib/public/User/Backend/AbstractBackend.php +++ b/lib/public/User/Backend/ABackend.php @@ -31,7 +31,7 @@ use OCP\UserInterface; /** * @since 14.0.0 */ -abstract class AbstractBackend implements IUserBackend, UserInterface { +abstract class ABackend implements IUserBackend, UserInterface { /** * @deprecated 14.0.0 From b723a2b8cada8c742ea1cadbbad2319c737cca9b Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 22 Mar 2018 15:54:55 +0100 Subject: [PATCH 8/9] Document parameters Signed-off-by: Roeland Jago Douma --- lib/public/User/Backend/ABackend.php | 3 +++ lib/public/User/Backend/ICheckPasswordBackend.php | 4 ++++ lib/public/User/Backend/ICountUsersBackend.php | 2 ++ lib/public/User/Backend/ICreateUserBackend.php | 4 ++++ lib/public/User/Backend/IGetDisplayNameBackend.php | 3 +++ lib/public/User/Backend/IGetHomeBackend.php | 3 +++ lib/public/User/Backend/IProvideAvatarBackend.php | 3 +++ lib/public/User/Backend/ISetDisplayNameBackend.php | 4 ++++ lib/public/User/Backend/ISetPasswordBackend.php | 4 ++++ 9 files changed, 30 insertions(+) diff --git a/lib/public/User/Backend/ABackend.php b/lib/public/User/Backend/ABackend.php index 48d410737d..a110ba5202 100644 --- a/lib/public/User/Backend/ABackend.php +++ b/lib/public/User/Backend/ABackend.php @@ -35,6 +35,9 @@ abstract class ABackend implements IUserBackend, UserInterface { /** * @deprecated 14.0.0 + * + * @param int $actions The action to check for + * @return bool */ public function implementsActions($actions): bool { $implements = 0; diff --git a/lib/public/User/Backend/ICheckPasswordBackend.php b/lib/public/User/Backend/ICheckPasswordBackend.php index 858c2d8c7d..b28c94f1a6 100644 --- a/lib/public/User/Backend/ICheckPasswordBackend.php +++ b/lib/public/User/Backend/ICheckPasswordBackend.php @@ -30,6 +30,10 @@ namespace OCP\User\Backend; interface ICheckPasswordBackend { /** * @since 14.0.0 + * + * @param string $uid The username + * @param string $password The password + * @return string|bool The uid on success false on failure */ public function checkPassword(string $loginName, string $password); } diff --git a/lib/public/User/Backend/ICountUsersBackend.php b/lib/public/User/Backend/ICountUsersBackend.php index 358557920d..1cb46712aa 100644 --- a/lib/public/User/Backend/ICountUsersBackend.php +++ b/lib/public/User/Backend/ICountUsersBackend.php @@ -31,6 +31,8 @@ interface ICountUsersBackend { /** * @since 14.0.0 + * + * @return int|bool The number of users on success false on failure */ public function countUsers(); } diff --git a/lib/public/User/Backend/ICreateUserBackend.php b/lib/public/User/Backend/ICreateUserBackend.php index d3454c613c..09a20e1245 100644 --- a/lib/public/User/Backend/ICreateUserBackend.php +++ b/lib/public/User/Backend/ICreateUserBackend.php @@ -31,6 +31,10 @@ interface ICreateUserBackend { /** * @since 14.0.0 + * + * @param string $uid The username of the user to create + * @param string $password The password of the new user + * @return bool */ public function createUser(string $uid, string $password): bool; } diff --git a/lib/public/User/Backend/IGetDisplayNameBackend.php b/lib/public/User/Backend/IGetDisplayNameBackend.php index f703e17157..6382ddd6eb 100644 --- a/lib/public/User/Backend/IGetDisplayNameBackend.php +++ b/lib/public/User/Backend/IGetDisplayNameBackend.php @@ -31,6 +31,9 @@ interface IGetDisplayNameBackend { /** * @since 14.0.0 + * + * @param string $uid user ID of the user + * @return string display name */ public function getDisplayName($uid): string; } diff --git a/lib/public/User/Backend/IGetHomeBackend.php b/lib/public/User/Backend/IGetHomeBackend.php index 607070932e..20fcd004bb 100644 --- a/lib/public/User/Backend/IGetHomeBackend.php +++ b/lib/public/User/Backend/IGetHomeBackend.php @@ -31,6 +31,9 @@ interface IGetHomeBackend { /** * @since 14.0.0 + * + * @param string $uid the username + * @return string|bool Datadir on success false on failure */ public function getHome(string $uid); } diff --git a/lib/public/User/Backend/IProvideAvatarBackend.php b/lib/public/User/Backend/IProvideAvatarBackend.php index 9aefda0e27..328c7450b4 100644 --- a/lib/public/User/Backend/IProvideAvatarBackend.php +++ b/lib/public/User/Backend/IProvideAvatarBackend.php @@ -31,6 +31,9 @@ interface IProvideAvatarBackend { /** * @since 14.0.0 + * + * @param string $uid + * @return bool */ public function canChangeAvatar(string $uid): bool; } diff --git a/lib/public/User/Backend/ISetDisplayNameBackend.php b/lib/public/User/Backend/ISetDisplayNameBackend.php index 23f8478282..ac41cd3e2c 100644 --- a/lib/public/User/Backend/ISetDisplayNameBackend.php +++ b/lib/public/User/Backend/ISetDisplayNameBackend.php @@ -31,6 +31,10 @@ interface ISetDisplayNameBackend { /** * @since 14.0.0 + * + * @param string $uid The username + * @param string $displayName The new display name + * @return bool */ public function setDisplayName(string $uid, string $displayName): bool; } diff --git a/lib/public/User/Backend/ISetPasswordBackend.php b/lib/public/User/Backend/ISetPasswordBackend.php index ec008b33a5..687ac5f70b 100644 --- a/lib/public/User/Backend/ISetPasswordBackend.php +++ b/lib/public/User/Backend/ISetPasswordBackend.php @@ -31,6 +31,10 @@ interface ISetPasswordBackend { /** * @since 14.0.0 + * + * @param string $uid The username + * @param string $password The new password + * @return bool */ public function setPassword(string $uid, string $password): bool; } From f5ce2531d80bd4e0d598571648658d6de1b6d15f Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 22 Mar 2018 09:17:39 +0100 Subject: [PATCH 9/9] Update autoloader Signed-off-by: Roeland Jago Douma --- lib/composer/composer/autoload_classmap.php | 9 +++++++++ lib/composer/composer/autoload_static.php | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index ecd7f155c0..032b7f5ea1 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -302,6 +302,15 @@ return array( 'OCP\\Template' => $baseDir . '/lib/public/Template.php', 'OCP\\User' => $baseDir . '/lib/public/User.php', 'OCP\\UserInterface' => $baseDir . '/lib/public/UserInterface.php', + 'OCP\\User\\Backend\\ABackend' => $baseDir . '/lib/public/User/Backend/ABackend.php', + 'OCP\\User\\Backend\\ICheckPasswordBackend' => $baseDir . '/lib/public/User/Backend/ICheckPasswordBackend.php', + 'OCP\\User\\Backend\\ICountUsersBackend' => $baseDir . '/lib/public/User/Backend/ICountUsersBackend.php', + 'OCP\\User\\Backend\\ICreateUserBackend' => $baseDir . '/lib/public/User/Backend/ICreateUserBackend.php', + 'OCP\\User\\Backend\\IGetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/IGetDisplayNameBackend.php', + 'OCP\\User\\Backend\\IGetHomeBackend' => $baseDir . '/lib/public/User/Backend/IGetHomeBackend.php', + 'OCP\\User\\Backend\\IProvideAvatarBackend' => $baseDir . '/lib/public/User/Backend/IProvideAvatarBackend.php', + 'OCP\\User\\Backend\\ISetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/ISetDisplayNameBackend.php', + 'OCP\\User\\Backend\\ISetPasswordBackend' => $baseDir . '/lib/public/User/Backend/ISetPasswordBackend.php', 'OCP\\Util' => $baseDir . '/lib/public/Util.php', 'OCP\\WorkflowEngine\\ICheck' => $baseDir . '/lib/public/WorkflowEngine/ICheck.php', 'OCP\\WorkflowEngine\\IManager' => $baseDir . '/lib/public/WorkflowEngine/IManager.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 8fbff8a1e1..8159a65f3c 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -332,6 +332,15 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Template' => __DIR__ . '/../../..' . '/lib/public/Template.php', 'OCP\\User' => __DIR__ . '/../../..' . '/lib/public/User.php', 'OCP\\UserInterface' => __DIR__ . '/../../..' . '/lib/public/UserInterface.php', + 'OCP\\User\\Backend\\ABackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ABackend.php', + 'OCP\\User\\Backend\\ICheckPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICheckPasswordBackend.php', + 'OCP\\User\\Backend\\ICountUsersBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICountUsersBackend.php', + 'OCP\\User\\Backend\\ICreateUserBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICreateUserBackend.php', + 'OCP\\User\\Backend\\IGetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetDisplayNameBackend.php', + 'OCP\\User\\Backend\\IGetHomeBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetHomeBackend.php', + 'OCP\\User\\Backend\\IProvideAvatarBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IProvideAvatarBackend.php', + 'OCP\\User\\Backend\\ISetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetDisplayNameBackend.php', + 'OCP\\User\\Backend\\ISetPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetPasswordBackend.php', 'OCP\\Util' => __DIR__ . '/../../..' . '/lib/public/Util.php', 'OCP\\WorkflowEngine\\ICheck' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/ICheck.php', 'OCP\\WorkflowEngine\\IManager' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IManager.php',