1
0

AlternativeHomeUserBackend.php 978 B

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