2010-04-22 17:03:54 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 15:07:57 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Aldo "xoen" Giambelluca <xoen@xoen.org>
|
|
|
|
* @author Andreas Fischer <bantu@owncloud.com>
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2016-07-21 15:07:57 +00:00
|
|
|
* @author Bart Visscher <bartv@thisnet.nl>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Bartek Przybylski <bart.p.pl@gmail.com>
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2016-04-25 12:10:55 +00:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
2017-11-06 19:15:27 +00:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Jakob Sack <mail@jakobsack.de>
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 16:13:36 +00:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2016-07-21 15:07:57 +00:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author shkdee <louis.traynard@m4x.org>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Tom Needham <tom@owncloud.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2011-04-15 15:14:02 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* @license AGPL-3.0
|
2011-04-15 15:14:02 +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.
|
2011-04-15 15:14:02 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2011-04-15 15:14:02 +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.
|
2011-04-15 15:14:02 +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/>
|
2011-04-15 15:14:02 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2018-04-25 13:22:28 +00:00
|
|
|
use OCP\ILogger;
|
|
|
|
|
2015-02-26 10:37:37 +00: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 21:19:26 +00:00
|
|
|
* Note that &run is deprecated and won't work anymore.
|
|
|
|
*
|
2015-02-26 10:37:37 +00: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 19:36:03 +00:00
|
|
|
class OC_User {
|
2014-04-21 13:44:54 +00:00
|
|
|
|
2013-05-28 22:32:10 +00:00
|
|
|
private static $_usedBackends = array();
|
|
|
|
|
|
|
|
private static $_setupedBackends = array();
|
|
|
|
|
2016-04-26 09:32:35 +00:00
|
|
|
// bool, stores if a user want to access a resource anonymously, e.g if they open a public link
|
2013-11-22 12:55:38 +00:00
|
|
|
private static $incognitoMode = false;
|
|
|
|
|
2011-04-15 15:14:02 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Adds the backend to the list of used backends
|
2015-02-02 15:09:30 +00:00
|
|
|
*
|
2016-01-14 13:28:03 +00:00
|
|
|
* @param string|\OCP\UserInterface $backend default: database The backend to use for user management
|
2013-05-28 22:32:10 +00:00
|
|
|
* @return bool
|
2011-04-15 15:14:02 +00:00
|
|
|
*
|
|
|
|
* Set the User Authentication Module
|
2017-07-19 17:44:10 +00:00
|
|
|
* @suppress PhanDeprecatedFunction
|
2011-04-15 15:14:02 +00:00
|
|
|
*/
|
2013-05-28 22:32:10 +00:00
|
|
|
public static function useBackend($backend = 'database') {
|
2016-01-14 13:28:03 +00:00
|
|
|
if ($backend instanceof \OCP\UserInterface) {
|
2013-05-28 22:32:10 +00:00
|
|
|
self::$_usedBackends[get_class($backend)] = $backend;
|
2015-12-17 12:03:37 +00:00
|
|
|
\OC::$server->getUserManager()->registerBackend($backend);
|
2012-12-11 13:56:04 +00:00
|
|
|
} else {
|
2012-07-19 14:31:55 +00:00
|
|
|
// You'll never know what happens
|
2013-05-28 22:32:10 +00:00
|
|
|
if (null === $backend OR !is_string($backend)) {
|
2012-07-19 14:31:55 +00:00
|
|
|
$backend = 'database';
|
|
|
|
}
|
2010-07-21 15:53:51 +00:00
|
|
|
|
2012-07-19 14:31:55 +00:00
|
|
|
// Load backend
|
2013-05-28 22:32:10 +00:00
|
|
|
switch ($backend) {
|
2012-07-19 14:31:55 +00:00
|
|
|
case 'database':
|
|
|
|
case 'mysql':
|
|
|
|
case 'sqlite':
|
2018-04-25 13:22:28 +00:00
|
|
|
\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
|
2016-05-04 06:34:39 +00:00
|
|
|
self::$_usedBackends[$backend] = new \OC\User\Database();
|
2015-12-17 12:03:37 +00:00
|
|
|
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
|
2012-07-19 14:31:55 +00:00
|
|
|
break;
|
2015-09-21 22:56:36 +00:00
|
|
|
case 'dummy':
|
|
|
|
self::$_usedBackends[$backend] = new \Test\Util\User\Dummy();
|
2015-12-17 12:03:37 +00:00
|
|
|
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
|
2015-09-21 22:56:36 +00:00
|
|
|
break;
|
2012-07-19 14:31:55 +00:00
|
|
|
default:
|
2018-04-25 13:22:28 +00:00
|
|
|
\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
|
2016-04-07 13:39:34 +00:00
|
|
|
$className = 'OC_USER_' . strtoupper($backend);
|
2012-07-19 14:31:55 +00:00
|
|
|
self::$_usedBackends[$backend] = new $className();
|
2015-12-17 12:03:37 +00:00
|
|
|
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
|
2012-07-19 14:31:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-07-21 15:53:51 +00:00
|
|
|
}
|
2012-12-11 13:56:04 +00:00
|
|
|
return true;
|
2010-07-21 15:53:51 +00:00
|
|
|
}
|
2010-07-19 16:52:49 +00:00
|
|
|
|
2012-07-23 20:31:48 +00:00
|
|
|
/**
|
|
|
|
* remove all used backends
|
|
|
|
*/
|
2012-09-07 13:22:01 +00:00
|
|
|
public static function clearBackends() {
|
2013-05-28 22:32:10 +00:00
|
|
|
self::$_usedBackends = array();
|
2015-12-17 12:03:37 +00:00
|
|
|
\OC::$server->getUserManager()->clearBackends();
|
2012-07-23 20:31:48 +00:00
|
|
|
}
|
|
|
|
|
2012-09-01 00:48:54 +00:00
|
|
|
/**
|
|
|
|
* setup the configured backends in config.php
|
2017-07-19 17:44:10 +00:00
|
|
|
* @suppress PhanDeprecatedFunction
|
2012-09-01 00:48:54 +00:00
|
|
|
*/
|
2012-09-07 13:22:01 +00:00
|
|
|
public static function setupBackends() {
|
2016-12-22 08:31:35 +00: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-28 22:32:10 +00:00
|
|
|
foreach ($backends as $i => $config) {
|
2016-12-22 08:31:35 +00:00
|
|
|
if (!is_array($config)) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-28 22:32:10 +00:00
|
|
|
$class = $config['class'];
|
|
|
|
$arguments = $config['arguments'];
|
|
|
|
if (class_exists($class)) {
|
|
|
|
if (array_search($i, self::$_setupedBackends) === false) {
|
2012-12-11 13:56:04 +00:00
|
|
|
// make a reflection object
|
|
|
|
$reflectionObj = new ReflectionClass($class);
|
2012-09-01 00:48:54 +00:00
|
|
|
|
2012-12-11 13:56:04 +00:00
|
|
|
// use Reflection to create a new instance, using the $args
|
|
|
|
$backend = $reflectionObj->newInstanceArgs($arguments);
|
|
|
|
self::useBackend($backend);
|
2013-06-18 18:47:47 +00:00
|
|
|
self::$_setupedBackends[] = $i;
|
2012-12-11 13:56:04 +00:00
|
|
|
} else {
|
2018-04-25 13:22:28 +00:00
|
|
|
\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
|
2012-12-11 13:56:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-04-25 13:22:28 +00:00
|
|
|
\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
|
2012-09-01 00:48:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-01 11:25:58 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Try to login a user, assuming authentication
|
2013-10-02 13:04:42 +00:00
|
|
|
* has already happened (e.g. via Single Sign On).
|
2013-10-01 11:25:58 +00:00
|
|
|
*
|
|
|
|
* Log in a user and regenerate a new session.
|
2013-10-02 13:04:42 +00:00
|
|
|
*
|
2013-10-02 13:11:49 +00:00
|
|
|
* @param \OCP\Authentication\IApacheBackend $backend
|
2013-10-02 13:04:42 +00:00
|
|
|
* @return bool
|
2013-10-01 11:25:58 +00:00
|
|
|
*/
|
2013-10-02 13:11:49 +00:00
|
|
|
public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
|
2013-10-01 11:25:58 +00:00
|
|
|
|
2013-10-01 20:56:47 +00:00
|
|
|
$uid = $backend->getCurrentUserId();
|
2013-10-01 11:25:58 +00:00
|
|
|
$run = true;
|
2018-09-14 15:23:06 +00:00
|
|
|
OC_Hook::emit("OC_User", "pre_login", array("run" => &$run, "uid" => $uid, 'backend' => $backend));
|
2013-10-01 11:25:58 +00:00
|
|
|
|
2015-02-02 15:09:30 +00:00
|
|
|
if ($uid) {
|
2015-08-21 15:31:58 +00:00
|
|
|
if (self::getUser() !== $uid) {
|
|
|
|
self::setUserId($uid);
|
2018-01-16 12:27:45 +00:00
|
|
|
$userSession = \OC::$server->getUserSession();
|
2017-01-20 09:46:29 +00:00
|
|
|
$userSession->setLoginName($uid);
|
2016-05-31 08:48:14 +00:00
|
|
|
$request = OC::$server->getRequest();
|
2017-01-20 09:46:29 +00:00
|
|
|
$userSession->createSessionToken($request, $uid, $uid);
|
2016-04-11 08:35:52 +00:00
|
|
|
// setup the filesystem
|
|
|
|
OC_Util::setupFS($uid);
|
2016-05-03 08:41:37 +00: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 05:26:41 +00:00
|
|
|
OC_Hook::emit(
|
|
|
|
'OC_User',
|
|
|
|
'post_login',
|
|
|
|
[
|
|
|
|
'uid' => $uid,
|
|
|
|
'password' => '',
|
|
|
|
'isTokenLogin' => false,
|
|
|
|
]
|
|
|
|
);
|
2016-04-11 08:35:52 +00:00
|
|
|
//trigger creation of user home and /files folder
|
|
|
|
\OC::$server->getUserFolder($uid);
|
2015-08-21 15:31:58 +00:00
|
|
|
}
|
2013-10-01 11:25:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Verify with Apache whether user is authenticated.
|
2013-10-01 11:25:58 +00:00
|
|
|
*
|
2013-10-02 13:04:42 +00:00
|
|
|
* @return boolean|null
|
|
|
|
* true: authenticated
|
|
|
|
* false: not authenticated
|
|
|
|
* null: not handled / no backend available
|
2013-10-01 11:25:58 +00:00
|
|
|
*/
|
2013-10-01 22:55:35 +00:00
|
|
|
public static function handleApacheAuth() {
|
2013-10-02 13:31:46 +00:00
|
|
|
$backend = self::findFirstActiveUsedBackend();
|
|
|
|
if ($backend) {
|
|
|
|
OC_App::loadApps();
|
2013-10-01 11:25:58 +00:00
|
|
|
|
2013-10-02 13:31:46 +00:00
|
|
|
//setup extra user backends
|
|
|
|
self::setupBackends();
|
2018-01-16 12:27:45 +00:00
|
|
|
\OC::$server->getUserSession()->unsetMagicInCookie();
|
2013-10-01 11:25:58 +00:00
|
|
|
|
2013-10-02 13:31:46 +00:00
|
|
|
return self::loginWithApache($backend);
|
2013-10-01 11:25:58 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 22:55:35 +00:00
|
|
|
return null;
|
2013-10-01 11:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-18 13:05:53 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Sets user id for session and triggers emit
|
2016-04-07 13:39:34 +00:00
|
|
|
*
|
|
|
|
* @param string $uid
|
2011-09-18 13:05:53 +00:00
|
|
|
*/
|
|
|
|
public static function setUserId($uid) {
|
2015-02-02 15:09:30 +00:00
|
|
|
$userSession = \OC::$server->getUserSession();
|
|
|
|
$userManager = \OC::$server->getUserManager();
|
|
|
|
if ($user = $userManager->get($uid)) {
|
|
|
|
$userSession->setUser($user);
|
|
|
|
} else {
|
|
|
|
\OC::$server->getSession()->set('user_id', $uid);
|
|
|
|
}
|
2010-07-21 15:53:51 +00:00
|
|
|
}
|
2010-07-19 16:52:49 +00:00
|
|
|
|
2010-04-22 17:03:54 +00:00
|
|
|
/**
|
2014-09-18 14:02:18 +00:00
|
|
|
* Check if the user is logged in, considers also the HTTP basic credentials
|
2015-02-02 15:09:30 +00:00
|
|
|
*
|
2016-04-07 13:39:34 +00:00
|
|
|
* @deprecated use \OC::$server->getUserSession()->isLoggedIn()
|
2014-05-11 17:05:28 +00:00
|
|
|
* @return bool
|
2010-07-22 21:42:18 +00:00
|
|
|
*/
|
2012-09-07 13:22:01 +00:00
|
|
|
public static function isLoggedIn() {
|
2016-04-07 13:39:34 +00:00
|
|
|
return \OC::$server->getUserSession()->isLoggedIn();
|
2010-07-21 15:53:51 +00:00
|
|
|
}
|
2010-07-19 16:52:49 +00:00
|
|
|
|
2013-11-22 12:55:38 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* set incognito mode, e.g. if a user wants to open a public link
|
2015-02-02 15:09:30 +00:00
|
|
|
*
|
2013-11-22 12:55:38 +00:00
|
|
|
* @param bool $status
|
|
|
|
*/
|
|
|
|
public static function setIncognitoMode($status) {
|
|
|
|
self::$incognitoMode = $status;
|
2014-12-17 20:53:43 +00:00
|
|
|
}
|
2013-11-22 12:55:38 +00:00
|
|
|
|
2014-12-17 20:53:43 +00:00
|
|
|
/**
|
|
|
|
* get incognito mode status
|
2015-02-02 15:09:30 +00:00
|
|
|
*
|
2014-12-17 20:53:43 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isIncognitoMode() {
|
|
|
|
return self::$incognitoMode;
|
2013-11-22 12:55:38 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 11:25:58 +00:00
|
|
|
/**
|
2017-08-18 10:16:43 +00:00
|
|
|
* Returns the current logout URL valid for the currently logged-in user
|
2013-10-01 11:25:58 +00:00
|
|
|
*
|
2017-08-18 13:32:40 +00:00
|
|
|
* @param \OCP\IURLGenerator $urlGenerator
|
2017-08-18 10:16:43 +00:00
|
|
|
* @return string
|
2013-10-01 11:25:58 +00:00
|
|
|
*/
|
2017-08-18 13:32:40 +00:00
|
|
|
public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
|
2013-10-02 13:31:46 +00:00
|
|
|
$backend = self::findFirstActiveUsedBackend();
|
|
|
|
if ($backend) {
|
2017-08-18 10:16:43 +00:00
|
|
|
return $backend->getLogoutUrl();
|
2013-10-01 11:25:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-07 20:56:44 +00:00
|
|
|
$logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
|
2019-01-23 15:16:31 +00:00
|
|
|
$logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
|
2016-04-18 10:14:07 +00:00
|
|
|
|
2017-08-18 10:16:43 +00:00
|
|
|
return $logoutUrl;
|
2013-10-01 11:25:58 +00:00
|
|
|
}
|
|
|
|
|
2013-01-14 18:45:17 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Check if the user is an admin user
|
2015-02-02 15:09:30 +00:00
|
|
|
*
|
2013-05-28 22:32:10 +00:00
|
|
|
* @param string $uid uid of the admin
|
|
|
|
* @return bool
|
2013-01-14 18:45:17 +00:00
|
|
|
*/
|
|
|
|
public static function isAdminUser($uid) {
|
2017-03-03 07:24:27 +00:00
|
|
|
$group = \OC::$server->getGroupManager()->get('admin');
|
|
|
|
$user = \OC::$server->getUserManager()->get($uid);
|
|
|
|
if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
|
2013-01-14 18:45:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-22 10:50:57 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* get the user id of the user currently logged in.
|
2015-02-02 15:09:30 +00:00
|
|
|
*
|
2015-05-21 11:07:54 +00:00
|
|
|
* @return string|bool uid or false
|
2011-06-22 10:50:57 +00:00
|
|
|
*/
|
2012-09-07 13:22:01 +00:00
|
|
|
public static function getUser() {
|
2014-07-16 17:40:22 +00:00
|
|
|
$uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null;
|
2013-11-22 12:55:38 +00:00
|
|
|
if (!is_null($uid) && self::$incognitoMode === false) {
|
2013-05-28 22:47:55 +00:00
|
|
|
return $uid;
|
2013-05-28 22:32:10 +00:00
|
|
|
} else {
|
2011-06-22 10:50:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 19:42:21 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* get the display name of the user currently logged in.
|
2015-02-02 15:09:30 +00:00
|
|
|
*
|
2013-06-03 11:15:42 +00:00
|
|
|
* @param string $uid
|
2017-07-19 17:44:10 +00:00
|
|
|
* @return string|bool uid or false
|
2018-03-25 18:42:03 +00:00
|
|
|
* @deprecated 8.1.0 fetch \OCP\IUser (has getDisplayName()) by using method
|
|
|
|
* get() of \OCP\IUserManager - \OC::$server->getUserManager()
|
2013-01-29 19:42:21 +00:00
|
|
|
*/
|
2013-06-03 11:15:42 +00:00
|
|
|
public static function getDisplayName($uid = null) {
|
|
|
|
if ($uid) {
|
2015-12-17 12:03:37 +00:00
|
|
|
$user = \OC::$server->getUserManager()->get($uid);
|
2013-06-03 11:15:42 +00:00
|
|
|
if ($user) {
|
|
|
|
return $user->getDisplayName();
|
|
|
|
} else {
|
|
|
|
return $uid;
|
|
|
|
}
|
2013-05-28 22:32:10 +00:00
|
|
|
} else {
|
2018-01-16 12:27:45 +00:00
|
|
|
$user = \OC::$server->getUserSession()->getUser();
|
2013-05-28 22:32:10 +00:00
|
|
|
if ($user) {
|
|
|
|
return $user->getDisplayName();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-29 19:42:21 +00:00
|
|
|
}
|
2013-01-24 12:07:59 +00:00
|
|
|
}
|
2013-01-29 19:42:21 +00:00
|
|
|
|
2010-04-22 17:03:54 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Set password
|
2015-02-02 15:09:30 +00:00
|
|
|
*
|
2013-05-28 22:32:10 +00: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 08:41:01 +00:00
|
|
|
*
|
|
|
|
* Change the password of a user
|
2010-07-22 21:42:18 +00:00
|
|
|
*/
|
2013-05-28 22:32:10 +00:00
|
|
|
public static function setPassword($uid, $password, $recoveryPassword = null) {
|
2015-12-17 12:03:37 +00:00
|
|
|
$user = \OC::$server->getUserManager()->get($uid);
|
2013-05-28 22:32:10 +00:00
|
|
|
if ($user) {
|
|
|
|
return $user->setPassword($password, $recoveryPassword);
|
|
|
|
} else {
|
2011-04-18 09:39:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-07-21 15:53:51 +00:00
|
|
|
}
|
2010-07-19 16:52:49 +00:00
|
|
|
|
2012-08-26 14:24:25 +00:00
|
|
|
/**
|
2013-01-28 18:08:03 +00:00
|
|
|
* @param string $uid The username
|
2013-05-28 22:32:10 +00:00
|
|
|
* @return string
|
2012-08-26 14:24:25 +00:00
|
|
|
*
|
2012-10-27 13:23:35 +00:00
|
|
|
* returns the path to the users home directory
|
2014-12-04 13:15:55 +00:00
|
|
|
* @deprecated Use \OC::$server->getUserManager->getHome()
|
2012-08-26 14:24:25 +00:00
|
|
|
*/
|
2012-09-07 13:22:01 +00:00
|
|
|
public static function getHome($uid) {
|
2015-12-17 12:03:37 +00:00
|
|
|
$user = \OC::$server->getUserManager()->get($uid);
|
2013-05-28 22:32:10 +00:00
|
|
|
if ($user) {
|
|
|
|
return $user->getHome();
|
|
|
|
} else {
|
2015-12-18 10:42:09 +00:00
|
|
|
return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
|
2012-08-26 14:24:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 19:42:21 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Get a list of all users display name
|
2015-02-02 15:09:30 +00:00
|
|
|
*
|
2013-05-28 22:32:10 +00: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 19:42:21 +00:00
|
|
|
*
|
|
|
|
* Get a list of all display names and user ids.
|
2014-12-09 17:36:40 +00:00
|
|
|
* @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead.
|
2013-01-29 19:42:21 +00:00
|
|
|
*/
|
|
|
|
public static function getDisplayNames($search = '', $limit = null, $offset = null) {
|
|
|
|
$displayNames = array();
|
2015-12-17 12:03:37 +00:00
|
|
|
$users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset);
|
2013-05-28 22:32:10 +00:00
|
|
|
foreach ($users as $user) {
|
|
|
|
$displayNames[$user->getUID()] = $user->getDisplayName();
|
2013-01-29 19:42:21 +00:00
|
|
|
}
|
|
|
|
return $displayNames;
|
2013-01-25 10:05:00 +00:00
|
|
|
}
|
2011-06-21 17:28:46 +00:00
|
|
|
|
2013-10-02 13:31:46 +00:00
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
* Returns the first active backend from self::$_usedBackends.
|
2015-02-02 15:09:30 +00:00
|
|
|
*
|
2014-02-06 15:30:58 +00:00
|
|
|
* @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
|
2013-10-02 13:31:46 +00:00
|
|
|
*/
|
|
|
|
private static function findFirstActiveUsedBackend() {
|
|
|
|
foreach (self::$_usedBackends as $backend) {
|
|
|
|
if ($backend instanceof OCP\Authentication\IApacheBackend) {
|
|
|
|
if ($backend->isSessionActive()) {
|
|
|
|
return $backend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|