AlternativeHomeUserBackend.php 964 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 ownCloud GmbH.
  4. * SPDX-License-Identifier: AGPL-3.0-only
  5. */
  6. namespace OCA\Testing;
  7. /**
  8. * Alternative home user backend.
  9. *
  10. * It returns a md5 of the home folder instead of the user id.
  11. * To configure, need to add this in config.php:
  12. * 'user_backends' => [
  13. * 'default' => false, [
  14. * 'class' => '\\OCA\\Testing\\AlternativeHomeUserBackend',
  15. * 'arguments' => [],
  16. * ],
  17. * ]
  18. */
  19. class AlternativeHomeUserBackend extends \OC\User\Database {
  20. public function __construct() {
  21. parent::__construct();
  22. }
  23. /**
  24. * get the user's home directory
  25. * @param string $uid the username
  26. * @return string|false
  27. */
  28. public function getHome($uid) {
  29. if ($this->userExists($uid)) {
  30. // workaround to avoid killing the admin
  31. if ($uid !== 'admin') {
  32. $uid = md5($uid);
  33. }
  34. return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid;
  35. }
  36. return false;
  37. }
  38. }