nextcloud/tests/lib/Util/User/Dummy.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

162 lines
3.2 KiB
PHP
Raw Normal View History

2012-04-13 16:52:06 -04:00
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
2013-05-28 17:46:57 -04:00
*/
2015-09-21 18:56:36 -04:00
namespace Test\Util\User;
use OC\User\Backend;
2015-09-21 18:56:36 -04:00
/**
* dummy user backend, does not keep state, only for testing use
*/
class Dummy extends Backend implements \OCP\IUserBackend {
private $users = [];
private $displayNames = [];
2013-05-28 17:46:57 -04:00
2012-04-13 16:52:06 -04:00
/**
* Create a new user
*
2013-05-28 17:46:57 -04:00
* @param string $uid The username of the user to create
* @param string $password The password of the new user
* @return bool
*
* Creates a new user. Basic checking of username is done in OC_User
* itself, not in its subclasses.
*/
2012-09-07 09:22:01 -04:00
public function createUser($uid, $password) {
2013-05-28 17:46:57 -04:00
if (isset($this->users[$uid])) {
2012-04-13 16:52:06 -04:00
return false;
2013-05-28 17:46:57 -04:00
} else {
$this->users[$uid] = $password;
2012-04-13 16:52:06 -04:00
return true;
}
}
/**
* delete a user
*
2013-05-28 17:46:57 -04:00
* @param string $uid The username of the user to delete
* @return bool
*
* Deletes a user
*/
public function deleteUser($uid) {
if (isset($this->users[$uid])) {
2012-04-13 16:52:06 -04:00
unset($this->users[$uid]);
return true;
2013-05-28 17:46:57 -04:00
} else {
2012-04-13 16:52:06 -04:00
return false;
}
}
/**
* Set password
*
2013-05-28 17:46:57 -04:00
* @param string $uid The username
* @param string $password The new password
* @return bool
*
* Change the password of a user
*/
2012-09-07 09:22:01 -04:00
public function setPassword($uid, $password) {
2013-05-28 17:46:57 -04:00
if (isset($this->users[$uid])) {
$this->users[$uid] = $password;
2012-04-13 16:52:06 -04:00
return true;
2013-05-28 17:46:57 -04:00
} else {
2012-04-13 16:52:06 -04:00
return false;
}
}
/**
* Check if the password is correct
*
2013-05-28 17:46:57 -04:00
* @param string $uid The username
* @param string $password The password
* @return string|bool
2013-05-28 17:46:57 -04:00
*
* Check if the password is correct without logging in the user
* returns the user id or false
*/
2012-09-07 09:22:01 -04:00
public function checkPassword($uid, $password) {
if (isset($this->users[$uid]) && $this->users[$uid] === $password) {
return $uid;
2012-04-13 16:52:06 -04:00
}
return false;
2012-04-13 16:52:06 -04:00
}
public function loginName2UserName($loginName) {
if (isset($this->users[strtolower($loginName)])) {
return strtolower($loginName);
}
return false;
}
2012-04-13 16:52:06 -04:00
/**
* Get a list of all users
*
2013-05-28 17:46:57 -04:00
* @param string $search
2015-06-27 14:35:47 -04:00
* @param null|int $limit
* @param null|int $offset
* @return string[] an array of all uids
2013-05-28 17:46:57 -04:00
*/
public function getUsers($search = '', $limit = null, $offset = null) {
if (empty($search)) {
return array_keys($this->users);
}
$result = [];
foreach (array_keys($this->users) as $user) {
if (stripos($user, $search) !== false) {
$result[] = $user;
}
}
return $result;
2012-04-13 16:52:06 -04:00
}
/**
* check if a user exists
*
2013-05-28 17:46:57 -04:00
* @param string $uid the username
* @return boolean
*/
2012-09-07 09:22:01 -04:00
public function userExists($uid) {
2012-04-13 16:52:06 -04:00
return isset($this->users[$uid]);
}
/**
* @return bool
*/
public function hasUserListings() {
return true;
}
2014-01-08 07:26:48 -05:00
/**
* counts the users in the database
*
2014-05-11 13:28:45 -04:00
* @return int|bool
2014-01-08 07:26:48 -05:00
*/
public function countUsers() {
return 0;
}
public function setDisplayName($uid, $displayName) {
$this->displayNames[$uid] = $displayName;
return true;
}
public function getDisplayName($uid) {
return $this->displayNames[$uid] ?? $uid;
}
/**
* Backend name to be shown in user management
* @return string the name of the backend to be shown
*/
public function getBackendName() {
return 'Dummy';
}
2012-04-13 16:52:06 -04:00
}