2012-04-13 20:52:06 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Andreas Fischer <bantu@owncloud.com>
|
|
|
|
* @author Arthur Schiwon <blizzz@owncloud.com>
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
|
|
|
* @author Robin McCorkell <rmccorkell@karoshi.org.uk>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2013-05-28 21:46:57 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
2013-05-28 21:46:57 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2013-05-28 21:46:57 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2013-05-28 21:46:57 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 10:44:34 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2013-05-28 21:46:57 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2013-05-28 21:46:57 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dummy user backend, does not keep state, only for testing use
|
|
|
|
*/
|
2014-12-12 16:25:03 +00:00
|
|
|
class OC_User_Dummy extends OC_User_Backend implements \OCP\IUserBackend {
|
2013-05-28 21:46:57 +00:00
|
|
|
private $users = array();
|
2014-11-06 16:22:59 +00:00
|
|
|
private $displayNames = array();
|
2013-05-28 21:46:57 +00:00
|
|
|
|
2012-04-13 20:52:06 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Create a new user
|
2014-11-06 16:22:59 +00:00
|
|
|
*
|
2013-05-28 21:46:57 +00: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 13:22:01 +00:00
|
|
|
public function createUser($uid, $password) {
|
2013-05-28 21:46:57 +00:00
|
|
|
if (isset($this->users[$uid])) {
|
2012-04-13 20:52:06 +00:00
|
|
|
return false;
|
2013-05-28 21:46:57 +00:00
|
|
|
} else {
|
|
|
|
$this->users[$uid] = $password;
|
2012-04-13 20:52:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* delete a user
|
2014-11-06 16:22:59 +00:00
|
|
|
*
|
2013-05-28 21:46:57 +00: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 20:52:06 +00:00
|
|
|
unset($this->users[$uid]);
|
|
|
|
return true;
|
2013-05-28 21:46:57 +00:00
|
|
|
} else {
|
2012-04-13 20:52:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Set password
|
2014-11-06 16:22:59 +00:00
|
|
|
*
|
2013-05-28 21:46:57 +00:00
|
|
|
* @param string $uid The username
|
|
|
|
* @param string $password The new password
|
|
|
|
* @return bool
|
|
|
|
*
|
|
|
|
* Change the password of a user
|
|
|
|
*/
|
2012-09-07 13:22:01 +00:00
|
|
|
public function setPassword($uid, $password) {
|
2013-05-28 21:46:57 +00:00
|
|
|
if (isset($this->users[$uid])) {
|
|
|
|
$this->users[$uid] = $password;
|
2012-04-13 20:52:06 +00:00
|
|
|
return true;
|
2013-05-28 21:46:57 +00:00
|
|
|
} else {
|
2012-04-13 20:52:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Check if the password is correct
|
2014-11-06 16:22:59 +00:00
|
|
|
*
|
2013-05-28 21:46:57 +00:00
|
|
|
* @param string $uid The username
|
|
|
|
* @param string $password The password
|
|
|
|
* @return string
|
|
|
|
*
|
|
|
|
* Check if the password is correct without logging in the user
|
|
|
|
* returns the user id or false
|
|
|
|
*/
|
2012-09-07 13:22:01 +00:00
|
|
|
public function checkPassword($uid, $password) {
|
2013-10-08 18:03:16 +00:00
|
|
|
if (isset($this->users[$uid]) && $this->users[$uid] === $password) {
|
2013-10-08 17:48:49 +00:00
|
|
|
return $uid;
|
2013-05-28 21:46:57 +00:00
|
|
|
} else {
|
2012-04-13 20:52:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Get a list of all users
|
2014-11-06 16:22:59 +00:00
|
|
|
*
|
2013-05-28 21:46:57 +00:00
|
|
|
* @param string $search
|
|
|
|
* @param int $limit
|
|
|
|
* @param int $offset
|
2014-02-06 15:30:58 +00:00
|
|
|
* @return string[] with all uids
|
2013-05-28 21:46:57 +00:00
|
|
|
*
|
|
|
|
* Get a list of all users.
|
|
|
|
*/
|
2012-09-01 18:49:50 +00:00
|
|
|
public function getUsers($search = '', $limit = null, $offset = null) {
|
2014-11-06 16:22:59 +00:00
|
|
|
if (empty($search)) {
|
2014-06-25 11:13:53 +00:00
|
|
|
return array_keys($this->users);
|
|
|
|
}
|
|
|
|
$result = array();
|
2014-11-06 16:22:59 +00:00
|
|
|
foreach (array_keys($this->users) as $user) {
|
|
|
|
if (stripos($user, $search) !== false) {
|
2014-06-25 11:13:53 +00:00
|
|
|
$result[] = $user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
2012-04-13 20:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* check if a user exists
|
2014-11-06 16:22:59 +00:00
|
|
|
*
|
2013-05-28 21:46:57 +00:00
|
|
|
* @param string $uid the username
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2012-09-07 13:22:01 +00:00
|
|
|
public function userExists($uid) {
|
2012-04-13 20:52:06 +00:00
|
|
|
return isset($this->users[$uid]);
|
|
|
|
}
|
2013-02-11 21:01:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasUserListings() {
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-08 12:26:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* counts the users in the database
|
|
|
|
*
|
2014-05-11 17:28:45 +00:00
|
|
|
* @return int|bool
|
2014-01-08 12:26:48 +00:00
|
|
|
*/
|
|
|
|
public function countUsers() {
|
|
|
|
return 0;
|
|
|
|
}
|
2014-11-06 16:22:59 +00:00
|
|
|
|
|
|
|
public function setDisplayName($uid, $displayName) {
|
|
|
|
$this->displayNames[$uid] = $displayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDisplayName($uid) {
|
|
|
|
return isset($this->displayNames[$uid])? $this->displayNames[$uid]: $uid;
|
|
|
|
}
|
2014-12-12 16:25:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 20:52:06 +00:00
|
|
|
}
|