1
0

AlternativeHomeUserBackend.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @author Vincent Petry <pvince81@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud GmbH.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OCA\Testing;
  22. /**
  23. * Alternative home user backend.
  24. *
  25. * It returns a md5 of the home folder instead of the user id.
  26. * To configure, need to add this in config.php:
  27. * 'user_backends' => [
  28. * 'default' => false, [
  29. * 'class' => '\\OCA\\Testing\\AlternativeHomeUserBackend',
  30. * 'arguments' => [],
  31. * ],
  32. * ]
  33. */
  34. class AlternativeHomeUserBackend extends \OC\User\Database {
  35. public function __construct() {
  36. parent::__construct();
  37. }
  38. /**
  39. * get the user's home directory
  40. * @param string $uid the username
  41. * @return string|false
  42. */
  43. public function getHome($uid) {
  44. if ($this->userExists($uid)) {
  45. // workaround to avoid killing the admin
  46. if ($uid !== 'admin') {
  47. $uid = md5($uid);
  48. }
  49. return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid;
  50. }
  51. return false;
  52. }
  53. }