2010-04-22 19:03:54 +02:00
|
|
|
<?php
|
2024-05-23 09:26:56 +02:00
|
|
|
|
2010-04-22 19:03:54 +02:00
|
|
|
/**
|
2024-05-23 09:26:56 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2011-04-15 17:14:02 +02:00
|
|
|
*/
|
2024-03-01 18:37:47 +01:00
|
|
|
use OC\Authentication\Token\IProvider;
|
2021-09-23 11:19:02 +02:00
|
|
|
use OC\User\LoginException;
|
2024-10-01 12:20:20 +02:00
|
|
|
use OCP\Authentication\Exceptions\InvalidTokenException;
|
|
|
|
use OCP\Authentication\Exceptions\WipeTokenException;
|
2024-03-15 12:51:31 +01:00
|
|
|
use OCP\Authentication\Token\IToken;
|
2021-06-01 13:59:40 +02:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2024-01-11 13:28:25 +01:00
|
|
|
use OCP\IGroupManager;
|
2024-03-22 01:04:48 +01:00
|
|
|
use OCP\ISession;
|
2024-01-11 13:28:25 +01:00
|
|
|
use OCP\IUser;
|
2021-06-01 13:59:40 +02:00
|
|
|
use OCP\IUserManager;
|
2024-01-11 13:28:25 +01:00
|
|
|
use OCP\Server;
|
2024-10-01 12:20:20 +02:00
|
|
|
use OCP\Session\Exceptions\SessionNotAvailableException;
|
2023-02-28 00:10:46 -01:00
|
|
|
use OCP\User\Events\BeforeUserLoggedInEvent;
|
2021-06-01 13:59:40 +02:00
|
|
|
use OCP\User\Events\UserLoggedInEvent;
|
2023-09-21 17:25:52 +02:00
|
|
|
use Psr\Log\LoggerInterface;
|
2018-04-25 15:22:28 +02:00
|
|
|
|
2015-02-26 11:37:37 +01:00
|
|
|
/**
|
|
|
|
* This class provides wrapper methods for user management. Multiple backends are
|
|
|
|
* supported. User management operations are delegated to the configured backend for
|
|
|
|
* execution.
|
|
|
|
*
|
2015-10-02 23:19:26 +02:00
|
|
|
* Note that &run is deprecated and won't work anymore.
|
|
|
|
*
|
2015-02-26 11:37:37 +01:00
|
|
|
* Hooks provided:
|
|
|
|
* pre_createUser(&run, uid, password)
|
|
|
|
* post_createUser(uid, password)
|
|
|
|
* pre_deleteUser(&run, uid)
|
|
|
|
* post_deleteUser(uid)
|
|
|
|
* pre_setPassword(&run, uid, password, recoveryPassword)
|
|
|
|
* post_setPassword(uid, password, recoveryPassword)
|
|
|
|
* pre_login(&run, uid, password)
|
|
|
|
* post_login(uid)
|
|
|
|
* logout()
|
|
|
|
*/
|
2011-07-29 21:36:03 +02:00
|
|
|
class OC_User {
|
2020-03-26 09:30:18 +01:00
|
|
|
private static $_setupedBackends = [];
|
2013-05-29 00:32:10 +02:00
|
|
|
|
2016-04-26 11:32:35 +02:00
|
|
|
// bool, stores if a user want to access a resource anonymously, e.g if they open a public link
|
2013-11-22 13:55:38 +01:00
|
|
|
private static $incognitoMode = false;
|
|
|
|
|
2011-04-15 17:14:02 +02:00
|
|
|
/**
|
2014-05-19 17:50:53 +02:00
|
|
|
* Adds the backend to the list of used backends
|
2015-02-02 16:09:30 +01:00
|
|
|
*
|
2016-01-14 14:28:03 +01:00
|
|
|
* @param string|\OCP\UserInterface $backend default: database The backend to use for user management
|
2013-05-29 00:32:10 +02:00
|
|
|
* @return bool
|
2025-04-10 11:12:25 +02:00
|
|
|
* @deprecated 32.0.0 Use IUserManager::registerBackend instead
|
2011-04-15 17:14:02 +02:00
|
|
|
*
|
|
|
|
* Set the User Authentication Module
|
|
|
|
*/
|
2013-05-29 00:32:10 +02:00
|
|
|
public static function useBackend($backend = 'database') {
|
2016-01-14 14:28:03 +01:00
|
|
|
if ($backend instanceof \OCP\UserInterface) {
|
2025-04-10 11:12:25 +02:00
|
|
|
Server::get(IUserManager::class)->registerBackend($backend);
|
2012-12-11 14:56:04 +01:00
|
|
|
} else {
|
2012-07-19 16:31:55 +02:00
|
|
|
// You'll never know what happens
|
2024-03-28 16:13:19 +01:00
|
|
|
if ($backend === null or !is_string($backend)) {
|
2012-07-19 16:31:55 +02:00
|
|
|
$backend = 'database';
|
|
|
|
}
|
2010-07-21 17:53:51 +02:00
|
|
|
|
2012-07-19 16:31:55 +02:00
|
|
|
// Load backend
|
2013-05-29 00:32:10 +02:00
|
|
|
switch ($backend) {
|
2012-07-19 16:31:55 +02:00
|
|
|
case 'database':
|
|
|
|
case 'mysql':
|
|
|
|
case 'sqlite':
|
2024-01-11 13:28:25 +01:00
|
|
|
Server::get(LoggerInterface::class)->debug('Adding user backend ' . $backend . '.', ['app' => 'core']);
|
2025-04-10 11:12:25 +02:00
|
|
|
Server::get(IUserManager::class)->registerBackend(new \OC\User\Database());
|
2012-07-19 16:31:55 +02:00
|
|
|
break;
|
2015-09-22 00:56:36 +02:00
|
|
|
case 'dummy':
|
2025-04-10 11:12:25 +02:00
|
|
|
Server::get(IUserManager::class)->registerBackend(new \Test\Util\User\Dummy());
|
2015-09-22 00:56:36 +02:00
|
|
|
break;
|
2012-07-19 16:31:55 +02:00
|
|
|
default:
|
2024-01-11 13:28:25 +01:00
|
|
|
Server::get(LoggerInterface::class)->debug('Adding default user backend ' . $backend . '.', ['app' => 'core']);
|
2016-04-07 15:39:34 +02:00
|
|
|
$className = 'OC_USER_' . strtoupper($backend);
|
2025-04-10 11:12:25 +02:00
|
|
|
Server::get(IUserManager::class)->registerBackend(new $className());
|
2012-07-19 16:31:55 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-07-21 17:53:51 +02:00
|
|
|
}
|
2012-12-11 14:56:04 +01:00
|
|
|
return true;
|
2010-07-21 17:53:51 +02:00
|
|
|
}
|
2010-07-19 18:52:49 +02:00
|
|
|
|
2012-07-23 22:31:48 +02:00
|
|
|
/**
|
|
|
|
* remove all used backends
|
2025-04-10 11:12:25 +02:00
|
|
|
* @deprecated 32.0.0 Use IUserManager::clearBackends instead
|
2012-07-23 22:31:48 +02:00
|
|
|
*/
|
2012-09-07 15:22:01 +02:00
|
|
|
public static function clearBackends() {
|
2025-04-10 11:12:25 +02:00
|
|
|
Server::get(IUserManager::class)->clearBackends();
|
2012-07-23 22:31:48 +02:00
|
|
|
}
|
|
|
|
|
2012-09-01 02:48:54 +02:00
|
|
|
/**
|
|
|
|
* setup the configured backends in config.php
|
2017-07-19 19:44:10 +02:00
|
|
|
* @suppress PhanDeprecatedFunction
|
2012-09-01 02:48:54 +02:00
|
|
|
*/
|
2012-09-07 15:22:01 +02:00
|
|
|
public static function setupBackends() {
|
2016-12-22 09:31:35 +01:00
|
|
|
OC_App::loadApps(['prelogin']);
|
|
|
|
$backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
|
|
|
|
if (isset($backends['default']) && !$backends['default']) {
|
|
|
|
// clear default backends
|
|
|
|
self::clearBackends();
|
|
|
|
}
|
2013-05-29 00:32:10 +02:00
|
|
|
foreach ($backends as $i => $config) {
|
2016-12-22 09:31:35 +01:00
|
|
|
if (!is_array($config)) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-29 00:32:10 +02:00
|
|
|
$class = $config['class'];
|
|
|
|
$arguments = $config['arguments'];
|
|
|
|
if (class_exists($class)) {
|
2023-09-17 10:43:23 +02:00
|
|
|
if (!in_array($i, self::$_setupedBackends)) {
|
2012-12-11 14:56:04 +01:00
|
|
|
// make a reflection object
|
|
|
|
$reflectionObj = new ReflectionClass($class);
|
2012-09-01 02:48:54 +02:00
|
|
|
|
2012-12-11 14:56:04 +01:00
|
|
|
// use Reflection to create a new instance, using the $args
|
|
|
|
$backend = $reflectionObj->newInstanceArgs($arguments);
|
|
|
|
self::useBackend($backend);
|
2013-06-18 21:47:47 +03:00
|
|
|
self::$_setupedBackends[] = $i;
|
2012-12-11 14:56:04 +01:00
|
|
|
} else {
|
2024-01-11 13:28:25 +01:00
|
|
|
Server::get(LoggerInterface::class)->debug('User backend ' . $class . ' already initialized.', ['app' => 'core']);
|
2012-12-11 14:56:04 +01:00
|
|
|
}
|
|
|
|
} else {
|
2024-01-11 13:28:25 +01:00
|
|
|
Server::get(LoggerInterface::class)->error('User backend ' . $class . ' not found.', ['app' => 'core']);
|
2012-09-01 02:48:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-01 13:25:58 +02:00
|
|
|
/**
|
2014-05-19 17:50:53 +02:00
|
|
|
* Try to login a user, assuming authentication
|
2013-10-02 15:04:42 +02:00
|
|
|
* has already happened (e.g. via Single Sign On).
|
2013-10-01 13:25:58 +02:00
|
|
|
*
|
|
|
|
* Log in a user and regenerate a new session.
|
2013-10-02 15:04:42 +02:00
|
|
|
*
|
2013-10-02 15:11:49 +02:00
|
|
|
* @param \OCP\Authentication\IApacheBackend $backend
|
2013-10-02 15:04:42 +02:00
|
|
|
* @return bool
|
2013-10-01 13:25:58 +02:00
|
|
|
*/
|
2013-10-02 15:11:49 +02:00
|
|
|
public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
|
2013-10-01 22:56:47 +02:00
|
|
|
$uid = $backend->getCurrentUserId();
|
2013-10-01 13:25:58 +02:00
|
|
|
$run = true;
|
2020-03-26 09:30:18 +01:00
|
|
|
OC_Hook::emit('OC_User', 'pre_login', ['run' => &$run, 'uid' => $uid, 'backend' => $backend]);
|
2013-10-01 13:25:58 +02:00
|
|
|
|
2015-02-02 16:09:30 +01:00
|
|
|
if ($uid) {
|
2015-08-21 17:31:58 +02:00
|
|
|
if (self::getUser() !== $uid) {
|
|
|
|
self::setUserId($uid);
|
2018-01-16 13:27:45 +01:00
|
|
|
$userSession = \OC::$server->getUserSession();
|
2023-02-28 00:10:46 -01:00
|
|
|
|
|
|
|
/** @var IEventDispatcher $dispatcher */
|
|
|
|
$dispatcher = \OC::$server->get(IEventDispatcher::class);
|
|
|
|
|
2021-09-23 11:19:02 +02:00
|
|
|
if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
|
2022-09-21 17:44:32 +02:00
|
|
|
$message = \OC::$server->getL10N('lib')->t('Account disabled');
|
2021-09-23 11:19:02 +02:00
|
|
|
throw new LoginException($message);
|
|
|
|
}
|
2017-01-20 10:46:29 +01:00
|
|
|
$userSession->setLoginName($uid);
|
2016-05-31 10:48:14 +02:00
|
|
|
$request = OC::$server->getRequest();
|
2021-07-12 19:22:04 +02:00
|
|
|
$password = null;
|
|
|
|
if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
|
|
|
|
$password = $backend->getCurrentUserSecret();
|
|
|
|
}
|
2023-02-28 00:10:46 -01:00
|
|
|
|
|
|
|
/** @var IEventDispatcher $dispatcher */
|
|
|
|
$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password, $backend));
|
|
|
|
|
2021-07-12 19:22:04 +02:00
|
|
|
$userSession->createSessionToken($request, $uid, $uid, $password);
|
2022-05-25 13:09:06 +02:00
|
|
|
$userSession->createRememberMeToken($userSession->getUser());
|
2024-03-01 18:37:47 +01:00
|
|
|
|
|
|
|
if (empty($password)) {
|
|
|
|
$tokenProvider = \OC::$server->get(IProvider::class);
|
2024-10-01 12:20:20 +02:00
|
|
|
try {
|
|
|
|
$token = $tokenProvider->getToken($userSession->getSession()->getId());
|
|
|
|
$token->setScope([
|
|
|
|
IToken::SCOPE_SKIP_PASSWORD_VALIDATION => true,
|
|
|
|
IToken::SCOPE_FILESYSTEM => true,
|
|
|
|
]);
|
|
|
|
$tokenProvider->updateToken($token);
|
|
|
|
} catch (InvalidTokenException|WipeTokenException|SessionNotAvailableException) {
|
|
|
|
// swallow the exceptions as we do not deal with them here
|
|
|
|
// simply skip updating the token when is it missing
|
|
|
|
}
|
2024-03-01 18:37:47 +01:00
|
|
|
}
|
|
|
|
|
2016-04-11 10:35:52 +02:00
|
|
|
// setup the filesystem
|
|
|
|
OC_Util::setupFS($uid);
|
2016-05-03 10:41:37 +02:00
|
|
|
// first call the post_login hooks, the login-process needs to be
|
|
|
|
// completed before we can safely create the users folder.
|
|
|
|
// For example encryption needs to initialize the users keys first
|
|
|
|
// before we can create the user folder with the skeleton files
|
2019-06-11 07:26:41 +02:00
|
|
|
OC_Hook::emit(
|
|
|
|
'OC_User',
|
|
|
|
'post_login',
|
|
|
|
[
|
|
|
|
'uid' => $uid,
|
2021-07-12 19:22:04 +02:00
|
|
|
'password' => $password,
|
2019-06-11 07:26:41 +02:00
|
|
|
'isTokenLogin' => false,
|
|
|
|
]
|
|
|
|
);
|
2021-06-01 13:59:40 +02:00
|
|
|
$dispatcher->dispatchTyped(new UserLoggedInEvent(
|
2023-01-20 11:45:08 +01:00
|
|
|
\OC::$server->get(IUserManager::class)->get($uid),
|
|
|
|
$uid,
|
|
|
|
null,
|
|
|
|
false)
|
2021-06-01 13:59:40 +02:00
|
|
|
);
|
|
|
|
|
2016-04-11 10:35:52 +02:00
|
|
|
//trigger creation of user home and /files folder
|
|
|
|
\OC::$server->getUserFolder($uid);
|
2015-08-21 17:31:58 +02:00
|
|
|
}
|
2013-10-01 13:25:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-19 17:50:53 +02:00
|
|
|
* Verify with Apache whether user is authenticated.
|
2013-10-01 13:25:58 +02:00
|
|
|
*
|
2013-10-02 15:04:42 +02:00
|
|
|
* @return boolean|null
|
|
|
|
* true: authenticated
|
|
|
|
* false: not authenticated
|
|
|
|
* null: not handled / no backend available
|
2013-10-01 13:25:58 +02:00
|
|
|
*/
|
2013-10-02 00:55:35 +02:00
|
|
|
public static function handleApacheAuth() {
|
2013-10-02 15:31:46 +02:00
|
|
|
$backend = self::findFirstActiveUsedBackend();
|
|
|
|
if ($backend) {
|
|
|
|
OC_App::loadApps();
|
2013-10-01 13:25:58 +02:00
|
|
|
|
2013-10-02 15:31:46 +02:00
|
|
|
//setup extra user backends
|
|
|
|
self::setupBackends();
|
2018-01-16 13:27:45 +01:00
|
|
|
\OC::$server->getUserSession()->unsetMagicInCookie();
|
2013-10-01 13:25:58 +02:00
|
|
|
|
2013-10-02 15:31:46 +02:00
|
|
|
return self::loginWithApache($backend);
|
2013-10-01 13:25:58 +02:00
|
|
|
}
|
|
|
|
|
2013-10-02 00:55:35 +02:00
|
|
|
return null;
|
2013-10-01 13:25:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-18 15:05:53 +02:00
|
|
|
/**
|
2014-05-19 17:50:53 +02:00
|
|
|
* Sets user id for session and triggers emit
|
2016-04-07 15:39:34 +02:00
|
|
|
*
|
|
|
|
* @param string $uid
|
2011-09-18 15:05:53 +02:00
|
|
|
*/
|
|
|
|
public static function setUserId($uid) {
|
2015-02-02 16:09:30 +01:00
|
|
|
$userSession = \OC::$server->getUserSession();
|
2025-04-10 11:12:25 +02:00
|
|
|
$userManager = Server::get(IUserManager::class);
|
2015-02-02 16:09:30 +01:00
|
|
|
if ($user = $userManager->get($uid)) {
|
|
|
|
$userSession->setUser($user);
|
|
|
|
} else {
|
|
|
|
\OC::$server->getSession()->set('user_id', $uid);
|
|
|
|
}
|
2010-07-21 17:53:51 +02:00
|
|
|
}
|
2010-07-19 18:52:49 +02:00
|
|
|
|
2010-04-22 19:03:54 +02:00
|
|
|
/**
|
2014-09-18 16:02:18 +02:00
|
|
|
* Check if the user is logged in, considers also the HTTP basic credentials
|
2015-02-02 16:09:30 +01:00
|
|
|
*
|
2024-09-18 23:51:06 +02:00
|
|
|
* @deprecated 12.0.0 use \OC::$server->getUserSession()->isLoggedIn()
|
2014-05-11 18:05:28 +01:00
|
|
|
* @return bool
|
2010-07-22 23:42:18 +02:00
|
|
|
*/
|
2012-09-07 15:22:01 +02:00
|
|
|
public static function isLoggedIn() {
|
2016-04-07 15:39:34 +02:00
|
|
|
return \OC::$server->getUserSession()->isLoggedIn();
|
2010-07-21 17:53:51 +02:00
|
|
|
}
|
2010-07-19 18:52:49 +02:00
|
|
|
|
2013-11-22 13:55:38 +01:00
|
|
|
/**
|
2014-05-19 17:50:53 +02:00
|
|
|
* set incognito mode, e.g. if a user wants to open a public link
|
2015-02-02 16:09:30 +01:00
|
|
|
*
|
2013-11-22 13:55:38 +01:00
|
|
|
* @param bool $status
|
|
|
|
*/
|
|
|
|
public static function setIncognitoMode($status) {
|
|
|
|
self::$incognitoMode = $status;
|
2014-12-17 21:53:43 +01:00
|
|
|
}
|
2013-11-22 13:55:38 +01:00
|
|
|
|
2014-12-17 21:53:43 +01:00
|
|
|
/**
|
|
|
|
* get incognito mode status
|
2015-02-02 16:09:30 +01:00
|
|
|
*
|
2014-12-17 21:53:43 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isIncognitoMode() {
|
|
|
|
return self::$incognitoMode;
|
2013-11-22 13:55:38 +01:00
|
|
|
}
|
|
|
|
|
2013-10-01 13:25:58 +02:00
|
|
|
/**
|
2017-08-18 12:16:43 +02:00
|
|
|
* Returns the current logout URL valid for the currently logged-in user
|
2013-10-01 13:25:58 +02:00
|
|
|
*
|
2017-08-18 15:32:40 +02:00
|
|
|
* @param \OCP\IURLGenerator $urlGenerator
|
2017-08-18 12:16:43 +02:00
|
|
|
* @return string
|
2013-10-01 13:25:58 +02:00
|
|
|
*/
|
2017-08-18 15:32:40 +02:00
|
|
|
public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
|
2013-10-02 15:31:46 +02:00
|
|
|
$backend = self::findFirstActiveUsedBackend();
|
|
|
|
if ($backend) {
|
2017-08-18 12:16:43 +02:00
|
|
|
return $backend->getLogoutUrl();
|
2013-10-01 13:25:58 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 10:42:40 +02:00
|
|
|
$user = \OC::$server->getUserSession()->getUser();
|
2024-01-11 13:28:25 +01:00
|
|
|
if ($user instanceof IUser) {
|
2020-07-23 10:42:40 +02:00
|
|
|
$backend = $user->getBackend();
|
|
|
|
if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
|
|
|
|
return $backend->getLogoutUrl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 22:56:44 +02:00
|
|
|
$logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
|
2019-01-23 16:16:31 +01:00
|
|
|
$logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
|
2016-04-18 12:14:07 +02:00
|
|
|
|
2017-08-18 12:16:43 +02:00
|
|
|
return $logoutUrl;
|
2013-10-01 13:25:58 +02:00
|
|
|
}
|
|
|
|
|
2013-01-14 19:45:17 +01:00
|
|
|
/**
|
2014-05-19 17:50:53 +02:00
|
|
|
* Check if the user is an admin user
|
2015-02-02 16:09:30 +01:00
|
|
|
*
|
2013-05-29 00:32:10 +02:00
|
|
|
* @param string $uid uid of the admin
|
|
|
|
* @return bool
|
2013-01-14 19:45:17 +01:00
|
|
|
*/
|
|
|
|
public static function isAdminUser($uid) {
|
2024-01-11 13:28:25 +01:00
|
|
|
$user = Server::get(IUserManager::class)->get($uid);
|
|
|
|
$isAdmin = $user && Server::get(IGroupManager::class)->isAdmin($user->getUID());
|
|
|
|
return $isAdmin && self::$incognitoMode === false;
|
2013-01-14 19:45:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-22 12:50:57 +02:00
|
|
|
/**
|
2014-05-19 17:50:53 +02:00
|
|
|
* get the user id of the user currently logged in.
|
2015-02-02 16:09:30 +01:00
|
|
|
*
|
2022-01-31 15:53:28 +01:00
|
|
|
* @return string|false uid or false
|
2011-06-22 12:50:57 +02:00
|
|
|
*/
|
2012-09-07 15:22:01 +02:00
|
|
|
public static function getUser() {
|
2024-03-22 01:04:48 +01:00
|
|
|
$uid = Server::get(ISession::class)?->get('user_id');
|
2013-11-22 13:55:38 +01:00
|
|
|
if (!is_null($uid) && self::$incognitoMode === false) {
|
2013-05-29 00:47:55 +02:00
|
|
|
return $uid;
|
2013-05-29 00:32:10 +02:00
|
|
|
} else {
|
2011-06-22 12:50:57 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-22 19:03:54 +02:00
|
|
|
/**
|
2014-05-19 17:50:53 +02:00
|
|
|
* Set password
|
2015-02-02 16:09:30 +01:00
|
|
|
*
|
2013-05-29 00:32:10 +02:00
|
|
|
* @param string $uid The username
|
|
|
|
* @param string $password The new password
|
|
|
|
* @param string $recoveryPassword for the encryption app to reset encryption keys
|
|
|
|
* @return bool
|
2011-04-18 10:41:01 +02:00
|
|
|
*
|
|
|
|
* Change the password of a user
|
2010-07-22 23:42:18 +02:00
|
|
|
*/
|
2013-05-29 00:32:10 +02:00
|
|
|
public static function setPassword($uid, $password, $recoveryPassword = null) {
|
2025-04-10 11:12:25 +02:00
|
|
|
$user = Server::get(IUserManager::class)->get($uid);
|
2013-05-29 00:32:10 +02:00
|
|
|
if ($user) {
|
|
|
|
return $user->setPassword($password, $recoveryPassword);
|
|
|
|
} else {
|
2011-04-18 11:39:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
2010-07-21 17:53:51 +02:00
|
|
|
}
|
2010-07-19 18:52:49 +02:00
|
|
|
|
2012-08-26 16:24:25 +02:00
|
|
|
/**
|
2013-01-28 19:08:03 +01:00
|
|
|
* @param string $uid The username
|
2013-05-29 00:32:10 +02:00
|
|
|
* @return string
|
2012-08-26 16:24:25 +02:00
|
|
|
*
|
2012-10-27 15:23:35 +02:00
|
|
|
* returns the path to the users home directory
|
2024-09-18 23:51:06 +02:00
|
|
|
* @deprecated 12.0.0 Use \OC::$server->getUserManager->getHome()
|
2012-08-26 16:24:25 +02:00
|
|
|
*/
|
2012-09-07 15:22:01 +02:00
|
|
|
public static function getHome($uid) {
|
2025-04-10 11:12:25 +02:00
|
|
|
$user = Server::get(IUserManager::class)->get($uid);
|
2013-05-29 00:32:10 +02:00
|
|
|
if ($user) {
|
|
|
|
return $user->getHome();
|
|
|
|
} else {
|
2015-12-18 11:42:09 +01:00
|
|
|
return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
|
2012-08-26 16:24:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 20:42:21 +01:00
|
|
|
/**
|
2014-05-19 17:50:53 +02:00
|
|
|
* Get a list of all users display name
|
2015-02-02 16:09:30 +01:00
|
|
|
*
|
2013-05-29 00:32:10 +02:00
|
|
|
* @param string $search
|
|
|
|
* @param int $limit
|
|
|
|
* @param int $offset
|
|
|
|
* @return array associative array with all display names (value) and corresponding uids (key)
|
2013-01-29 20:42:21 +01:00
|
|
|
*
|
|
|
|
* Get a list of all display names and user ids.
|
2024-09-18 23:51:06 +02:00
|
|
|
* @deprecated 12.0.0 Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead.
|
2013-01-29 20:42:21 +01:00
|
|
|
*/
|
|
|
|
public static function getDisplayNames($search = '', $limit = null, $offset = null) {
|
2020-03-26 09:30:18 +01:00
|
|
|
$displayNames = [];
|
2025-04-10 11:12:25 +02:00
|
|
|
$users = Server::get(IUserManager::class)->searchDisplayName($search, $limit, $offset);
|
2013-05-29 00:32:10 +02:00
|
|
|
foreach ($users as $user) {
|
|
|
|
$displayNames[$user->getUID()] = $user->getDisplayName();
|
2013-01-29 20:42:21 +01:00
|
|
|
}
|
|
|
|
return $displayNames;
|
2013-01-25 11:05:00 +01:00
|
|
|
}
|
2011-06-21 19:28:46 +02:00
|
|
|
|
2013-10-02 15:31:46 +02:00
|
|
|
/**
|
2014-05-19 17:50:53 +02:00
|
|
|
* Returns the first active backend from self::$_usedBackends.
|
2015-02-02 16:09:30 +01:00
|
|
|
*
|
2014-02-06 16:30:58 +01:00
|
|
|
* @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
|
2013-10-02 15:31:46 +02:00
|
|
|
*/
|
|
|
|
private static function findFirstActiveUsedBackend() {
|
2025-04-10 11:12:25 +02:00
|
|
|
foreach (Server::get(IUserManager::class)->getBackends() as $backend) {
|
2013-10-02 15:31:46 +02:00
|
|
|
if ($backend instanceof OCP\Authentication\IApacheBackend) {
|
|
|
|
if ($backend->isSessionActive()) {
|
|
|
|
return $backend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2010-04-22 19:03:54 +02:00
|
|
|
}
|