2012-04-14 00:52:06 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2013-05-29 01:46:57 +04:00
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Frank Karlitschek
|
|
|
|
* @copyright 2012 Frank Karlitschek frank@owncloud.org
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2012-04-14 00:52:06 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dummy user backend, does not keep state, only for testing use
|
|
|
|
*/
|
|
|
|
class OC_User_Dummy extends OC_User_Backend {
|
2013-05-29 01:46:57 +04:00
|
|
|
private $users = array();
|
|
|
|
|
2012-04-14 00:52:06 +04:00
|
|
|
/**
|
2013-05-29 01:46:57 +04:00
|
|
|
* @brief Create a new user
|
|
|
|
* @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 17:22:01 +04:00
|
|
|
public function createUser($uid, $password) {
|
2013-05-29 01:46:57 +04:00
|
|
|
if (isset($this->users[$uid])) {
|
2012-04-14 00:52:06 +04:00
|
|
|
return false;
|
2013-05-29 01:46:57 +04:00
|
|
|
} else {
|
|
|
|
$this->users[$uid] = $password;
|
2012-04-14 00:52:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-29 01:46:57 +04:00
|
|
|
* @brief delete a user
|
|
|
|
* @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-14 00:52:06 +04:00
|
|
|
unset($this->users[$uid]);
|
|
|
|
return true;
|
2013-05-29 01:46:57 +04:00
|
|
|
} else {
|
2012-04-14 00:52:06 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-29 01:46:57 +04:00
|
|
|
* @brief Set password
|
|
|
|
* @param string $uid The username
|
|
|
|
* @param string $password The new password
|
|
|
|
* @return bool
|
|
|
|
*
|
|
|
|
* Change the password of a user
|
|
|
|
*/
|
2012-09-07 17:22:01 +04:00
|
|
|
public function setPassword($uid, $password) {
|
2013-05-29 01:46:57 +04:00
|
|
|
if (isset($this->users[$uid])) {
|
|
|
|
$this->users[$uid] = $password;
|
2012-04-14 00:52:06 +04:00
|
|
|
return true;
|
2013-05-29 01:46:57 +04:00
|
|
|
} else {
|
2012-04-14 00:52:06 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-29 01:46:57 +04:00
|
|
|
* @brief Check if the password is correct
|
|
|
|
* @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 17:22:01 +04:00
|
|
|
public function checkPassword($uid, $password) {
|
2013-10-08 22:03:16 +04:00
|
|
|
if (isset($this->users[$uid]) && $this->users[$uid] === $password) {
|
2013-10-08 21:48:49 +04:00
|
|
|
return $uid;
|
2013-05-29 01:46:57 +04:00
|
|
|
} else {
|
2012-04-14 00:52:06 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-29 01:46:57 +04:00
|
|
|
* @brief Get a list of all users
|
|
|
|
* @param string $search
|
|
|
|
* @param int $limit
|
|
|
|
* @param int $offset
|
2014-02-06 19:30:58 +04:00
|
|
|
* @return string[] with all uids
|
2013-05-29 01:46:57 +04:00
|
|
|
*
|
|
|
|
* Get a list of all users.
|
|
|
|
*/
|
2012-09-01 22:49:50 +04:00
|
|
|
public function getUsers($search = '', $limit = null, $offset = null) {
|
2012-04-14 00:52:06 +04:00
|
|
|
return array_keys($this->users);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-29 01:46:57 +04:00
|
|
|
* @brief check if a user exists
|
|
|
|
* @param string $uid the username
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2012-09-07 17:22:01 +04:00
|
|
|
public function userExists($uid) {
|
2012-04-14 00:52:06 +04:00
|
|
|
return isset($this->users[$uid]);
|
|
|
|
}
|
2013-02-12 01:01:52 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasUserListings() {
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-08 16:26:48 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* counts the users in the database
|
|
|
|
*
|
|
|
|
* @return int | bool
|
|
|
|
*/
|
|
|
|
public function countUsers() {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-14 00:52:06 +04:00
|
|
|
}
|