Passed
Push — master ( 6ea8f6...845849 )
by Christoph
17:42 queued 15s
created
lib/private/legacy/OC_User.php 1 patch
Indentation   +366 added lines, -366 removed lines patch added patch discarded remove patch
@@ -60,370 +60,370 @@
 block discarded – undo
60 60
  *   logout()
61 61
  */
62 62
 class OC_User {
63
-	private static $_usedBackends = [];
64
-
65
-	private static $_setupedBackends = [];
66
-
67
-	// bool, stores if a user want to access a resource anonymously, e.g if they open a public link
68
-	private static $incognitoMode = false;
69
-
70
-	/**
71
-	 * Adds the backend to the list of used backends
72
-	 *
73
-	 * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
74
-	 * @return bool
75
-	 *
76
-	 * Set the User Authentication Module
77
-	 * @suppress PhanDeprecatedFunction
78
-	 */
79
-	public static function useBackend($backend = 'database') {
80
-		if ($backend instanceof \OCP\UserInterface) {
81
-			self::$_usedBackends[get_class($backend)] = $backend;
82
-			\OC::$server->getUserManager()->registerBackend($backend);
83
-		} else {
84
-			// You'll never know what happens
85
-			if (null === $backend or !is_string($backend)) {
86
-				$backend = 'database';
87
-			}
88
-
89
-			// Load backend
90
-			switch ($backend) {
91
-				case 'database':
92
-				case 'mysql':
93
-				case 'sqlite':
94
-					\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
95
-					self::$_usedBackends[$backend] = new \OC\User\Database();
96
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
97
-					break;
98
-				case 'dummy':
99
-					self::$_usedBackends[$backend] = new \Test\Util\User\Dummy();
100
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
101
-					break;
102
-				default:
103
-					\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
104
-					$className = 'OC_USER_' . strtoupper($backend);
105
-					self::$_usedBackends[$backend] = new $className();
106
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
107
-					break;
108
-			}
109
-		}
110
-		return true;
111
-	}
112
-
113
-	/**
114
-	 * remove all used backends
115
-	 */
116
-	public static function clearBackends() {
117
-		self::$_usedBackends = [];
118
-		\OC::$server->getUserManager()->clearBackends();
119
-	}
120
-
121
-	/**
122
-	 * setup the configured backends in config.php
123
-	 * @suppress PhanDeprecatedFunction
124
-	 */
125
-	public static function setupBackends() {
126
-		OC_App::loadApps(['prelogin']);
127
-		$backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
128
-		if (isset($backends['default']) && !$backends['default']) {
129
-			// clear default backends
130
-			self::clearBackends();
131
-		}
132
-		foreach ($backends as $i => $config) {
133
-			if (!is_array($config)) {
134
-				continue;
135
-			}
136
-			$class = $config['class'];
137
-			$arguments = $config['arguments'];
138
-			if (class_exists($class)) {
139
-				if (array_search($i, self::$_setupedBackends) === false) {
140
-					// make a reflection object
141
-					$reflectionObj = new ReflectionClass($class);
142
-
143
-					// use Reflection to create a new instance, using the $args
144
-					$backend = $reflectionObj->newInstanceArgs($arguments);
145
-					self::useBackend($backend);
146
-					self::$_setupedBackends[] = $i;
147
-				} else {
148
-					\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
149
-				}
150
-			} else {
151
-				\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
152
-			}
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Try to login a user, assuming authentication
158
-	 * has already happened (e.g. via Single Sign On).
159
-	 *
160
-	 * Log in a user and regenerate a new session.
161
-	 *
162
-	 * @param \OCP\Authentication\IApacheBackend $backend
163
-	 * @return bool
164
-	 */
165
-	public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
166
-		$uid = $backend->getCurrentUserId();
167
-		$run = true;
168
-		OC_Hook::emit("OC_User", "pre_login", ["run" => &$run, "uid" => $uid, 'backend' => $backend]);
169
-
170
-		if ($uid) {
171
-			if (self::getUser() !== $uid) {
172
-				self::setUserId($uid);
173
-				$userSession = \OC::$server->getUserSession();
174
-				$userSession->setLoginName($uid);
175
-				$request = OC::$server->getRequest();
176
-				$userSession->createSessionToken($request, $uid, $uid);
177
-				// setup the filesystem
178
-				OC_Util::setupFS($uid);
179
-				// first call the post_login hooks, the login-process needs to be
180
-				// completed before we can safely create the users folder.
181
-				// For example encryption needs to initialize the users keys first
182
-				// before we can create the user folder with the skeleton files
183
-				OC_Hook::emit(
184
-					'OC_User',
185
-					'post_login',
186
-					[
187
-						'uid' => $uid,
188
-						'password' => '',
189
-						'isTokenLogin' => false,
190
-					]
191
-				);
192
-				/** @var IEventDispatcher $dispatcher */
193
-				$dispatcher = \OC::$server->get(IEventDispatcher::class);
194
-				$dispatcher->dispatchTyped(new UserLoggedInEvent(
195
-						\OC::$server->get(IUserManager::class)->get($uid),
196
-						$uid,
197
-						'',
198
-						false)
199
-				);
200
-
201
-				//trigger creation of user home and /files folder
202
-				\OC::$server->getUserFolder($uid);
203
-			}
204
-			return true;
205
-		}
206
-		return false;
207
-	}
208
-
209
-	/**
210
-	 * Verify with Apache whether user is authenticated.
211
-	 *
212
-	 * @return boolean|null
213
-	 *          true: authenticated
214
-	 *          false: not authenticated
215
-	 *          null: not handled / no backend available
216
-	 */
217
-	public static function handleApacheAuth() {
218
-		$backend = self::findFirstActiveUsedBackend();
219
-		if ($backend) {
220
-			OC_App::loadApps();
221
-
222
-			//setup extra user backends
223
-			self::setupBackends();
224
-			\OC::$server->getUserSession()->unsetMagicInCookie();
225
-
226
-			return self::loginWithApache($backend);
227
-		}
228
-
229
-		return null;
230
-	}
231
-
232
-
233
-	/**
234
-	 * Sets user id for session and triggers emit
235
-	 *
236
-	 * @param string $uid
237
-	 */
238
-	public static function setUserId($uid) {
239
-		$userSession = \OC::$server->getUserSession();
240
-		$userManager = \OC::$server->getUserManager();
241
-		if ($user = $userManager->get($uid)) {
242
-			$userSession->setUser($user);
243
-		} else {
244
-			\OC::$server->getSession()->set('user_id', $uid);
245
-		}
246
-	}
247
-
248
-	/**
249
-	 * Check if the user is logged in, considers also the HTTP basic credentials
250
-	 *
251
-	 * @deprecated use \OC::$server->getUserSession()->isLoggedIn()
252
-	 * @return bool
253
-	 */
254
-	public static function isLoggedIn() {
255
-		return \OC::$server->getUserSession()->isLoggedIn();
256
-	}
257
-
258
-	/**
259
-	 * set incognito mode, e.g. if a user wants to open a public link
260
-	 *
261
-	 * @param bool $status
262
-	 */
263
-	public static function setIncognitoMode($status) {
264
-		self::$incognitoMode = $status;
265
-	}
266
-
267
-	/**
268
-	 * get incognito mode status
269
-	 *
270
-	 * @return bool
271
-	 */
272
-	public static function isIncognitoMode() {
273
-		return self::$incognitoMode;
274
-	}
275
-
276
-	/**
277
-	 * Returns the current logout URL valid for the currently logged-in user
278
-	 *
279
-	 * @param \OCP\IURLGenerator $urlGenerator
280
-	 * @return string
281
-	 */
282
-	public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
283
-		$backend = self::findFirstActiveUsedBackend();
284
-		if ($backend) {
285
-			return $backend->getLogoutUrl();
286
-		}
287
-
288
-		$user = \OC::$server->getUserSession()->getUser();
289
-		if ($user instanceof \OCP\IUser) {
290
-			$backend = $user->getBackend();
291
-			if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
292
-				return $backend->getLogoutUrl();
293
-			}
294
-		}
295
-
296
-		$logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
297
-		$logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
298
-
299
-		return $logoutUrl;
300
-	}
301
-
302
-	/**
303
-	 * Check if the user is an admin user
304
-	 *
305
-	 * @param string $uid uid of the admin
306
-	 * @return bool
307
-	 */
308
-	public static function isAdminUser($uid) {
309
-		$group = \OC::$server->getGroupManager()->get('admin');
310
-		$user = \OC::$server->getUserManager()->get($uid);
311
-		if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
312
-			return true;
313
-		}
314
-		return false;
315
-	}
316
-
317
-
318
-	/**
319
-	 * get the user id of the user currently logged in.
320
-	 *
321
-	 * @return string|bool uid or false
322
-	 */
323
-	public static function getUser() {
324
-		$uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null;
325
-		if (!is_null($uid) && self::$incognitoMode === false) {
326
-			return $uid;
327
-		} else {
328
-			return false;
329
-		}
330
-	}
331
-
332
-	/**
333
-	 * get the display name of the user currently logged in.
334
-	 *
335
-	 * @param string $uid
336
-	 * @return string|bool uid or false
337
-	 * @deprecated 8.1.0 fetch \OCP\IUser (has getDisplayName()) by using method
338
-	 *                   get() of \OCP\IUserManager - \OC::$server->getUserManager()
339
-	 */
340
-	public static function getDisplayName($uid = null) {
341
-		if ($uid) {
342
-			$user = \OC::$server->getUserManager()->get($uid);
343
-			if ($user) {
344
-				return $user->getDisplayName();
345
-			} else {
346
-				return $uid;
347
-			}
348
-		} else {
349
-			$user = \OC::$server->getUserSession()->getUser();
350
-			if ($user) {
351
-				return $user->getDisplayName();
352
-			} else {
353
-				return false;
354
-			}
355
-		}
356
-	}
357
-
358
-	/**
359
-	 * Set password
360
-	 *
361
-	 * @param string $uid The username
362
-	 * @param string $password The new password
363
-	 * @param string $recoveryPassword for the encryption app to reset encryption keys
364
-	 * @return bool
365
-	 *
366
-	 * Change the password of a user
367
-	 */
368
-	public static function setPassword($uid, $password, $recoveryPassword = null) {
369
-		$user = \OC::$server->getUserManager()->get($uid);
370
-		if ($user) {
371
-			return $user->setPassword($password, $recoveryPassword);
372
-		} else {
373
-			return false;
374
-		}
375
-	}
376
-
377
-	/**
378
-	 * @param string $uid The username
379
-	 * @return string
380
-	 *
381
-	 * returns the path to the users home directory
382
-	 * @deprecated Use \OC::$server->getUserManager->getHome()
383
-	 */
384
-	public static function getHome($uid) {
385
-		$user = \OC::$server->getUserManager()->get($uid);
386
-		if ($user) {
387
-			return $user->getHome();
388
-		} else {
389
-			return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
390
-		}
391
-	}
392
-
393
-	/**
394
-	 * Get a list of all users display name
395
-	 *
396
-	 * @param string $search
397
-	 * @param int $limit
398
-	 * @param int $offset
399
-	 * @return array associative array with all display names (value) and corresponding uids (key)
400
-	 *
401
-	 * Get a list of all display names and user ids.
402
-	 * @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead.
403
-	 */
404
-	public static function getDisplayNames($search = '', $limit = null, $offset = null) {
405
-		$displayNames = [];
406
-		$users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset);
407
-		foreach ($users as $user) {
408
-			$displayNames[$user->getUID()] = $user->getDisplayName();
409
-		}
410
-		return $displayNames;
411
-	}
412
-
413
-	/**
414
-	 * Returns the first active backend from self::$_usedBackends.
415
-	 *
416
-	 * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
417
-	 */
418
-	private static function findFirstActiveUsedBackend() {
419
-		foreach (self::$_usedBackends as $backend) {
420
-			if ($backend instanceof OCP\Authentication\IApacheBackend) {
421
-				if ($backend->isSessionActive()) {
422
-					return $backend;
423
-				}
424
-			}
425
-		}
426
-
427
-		return null;
428
-	}
63
+    private static $_usedBackends = [];
64
+
65
+    private static $_setupedBackends = [];
66
+
67
+    // bool, stores if a user want to access a resource anonymously, e.g if they open a public link
68
+    private static $incognitoMode = false;
69
+
70
+    /**
71
+     * Adds the backend to the list of used backends
72
+     *
73
+     * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
74
+     * @return bool
75
+     *
76
+     * Set the User Authentication Module
77
+     * @suppress PhanDeprecatedFunction
78
+     */
79
+    public static function useBackend($backend = 'database') {
80
+        if ($backend instanceof \OCP\UserInterface) {
81
+            self::$_usedBackends[get_class($backend)] = $backend;
82
+            \OC::$server->getUserManager()->registerBackend($backend);
83
+        } else {
84
+            // You'll never know what happens
85
+            if (null === $backend or !is_string($backend)) {
86
+                $backend = 'database';
87
+            }
88
+
89
+            // Load backend
90
+            switch ($backend) {
91
+                case 'database':
92
+                case 'mysql':
93
+                case 'sqlite':
94
+                    \OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
95
+                    self::$_usedBackends[$backend] = new \OC\User\Database();
96
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
97
+                    break;
98
+                case 'dummy':
99
+                    self::$_usedBackends[$backend] = new \Test\Util\User\Dummy();
100
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
101
+                    break;
102
+                default:
103
+                    \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
104
+                    $className = 'OC_USER_' . strtoupper($backend);
105
+                    self::$_usedBackends[$backend] = new $className();
106
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
107
+                    break;
108
+            }
109
+        }
110
+        return true;
111
+    }
112
+
113
+    /**
114
+     * remove all used backends
115
+     */
116
+    public static function clearBackends() {
117
+        self::$_usedBackends = [];
118
+        \OC::$server->getUserManager()->clearBackends();
119
+    }
120
+
121
+    /**
122
+     * setup the configured backends in config.php
123
+     * @suppress PhanDeprecatedFunction
124
+     */
125
+    public static function setupBackends() {
126
+        OC_App::loadApps(['prelogin']);
127
+        $backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
128
+        if (isset($backends['default']) && !$backends['default']) {
129
+            // clear default backends
130
+            self::clearBackends();
131
+        }
132
+        foreach ($backends as $i => $config) {
133
+            if (!is_array($config)) {
134
+                continue;
135
+            }
136
+            $class = $config['class'];
137
+            $arguments = $config['arguments'];
138
+            if (class_exists($class)) {
139
+                if (array_search($i, self::$_setupedBackends) === false) {
140
+                    // make a reflection object
141
+                    $reflectionObj = new ReflectionClass($class);
142
+
143
+                    // use Reflection to create a new instance, using the $args
144
+                    $backend = $reflectionObj->newInstanceArgs($arguments);
145
+                    self::useBackend($backend);
146
+                    self::$_setupedBackends[] = $i;
147
+                } else {
148
+                    \OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
149
+                }
150
+            } else {
151
+                \OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
152
+            }
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Try to login a user, assuming authentication
158
+     * has already happened (e.g. via Single Sign On).
159
+     *
160
+     * Log in a user and regenerate a new session.
161
+     *
162
+     * @param \OCP\Authentication\IApacheBackend $backend
163
+     * @return bool
164
+     */
165
+    public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
166
+        $uid = $backend->getCurrentUserId();
167
+        $run = true;
168
+        OC_Hook::emit("OC_User", "pre_login", ["run" => &$run, "uid" => $uid, 'backend' => $backend]);
169
+
170
+        if ($uid) {
171
+            if (self::getUser() !== $uid) {
172
+                self::setUserId($uid);
173
+                $userSession = \OC::$server->getUserSession();
174
+                $userSession->setLoginName($uid);
175
+                $request = OC::$server->getRequest();
176
+                $userSession->createSessionToken($request, $uid, $uid);
177
+                // setup the filesystem
178
+                OC_Util::setupFS($uid);
179
+                // first call the post_login hooks, the login-process needs to be
180
+                // completed before we can safely create the users folder.
181
+                // For example encryption needs to initialize the users keys first
182
+                // before we can create the user folder with the skeleton files
183
+                OC_Hook::emit(
184
+                    'OC_User',
185
+                    'post_login',
186
+                    [
187
+                        'uid' => $uid,
188
+                        'password' => '',
189
+                        'isTokenLogin' => false,
190
+                    ]
191
+                );
192
+                /** @var IEventDispatcher $dispatcher */
193
+                $dispatcher = \OC::$server->get(IEventDispatcher::class);
194
+                $dispatcher->dispatchTyped(new UserLoggedInEvent(
195
+                        \OC::$server->get(IUserManager::class)->get($uid),
196
+                        $uid,
197
+                        '',
198
+                        false)
199
+                );
200
+
201
+                //trigger creation of user home and /files folder
202
+                \OC::$server->getUserFolder($uid);
203
+            }
204
+            return true;
205
+        }
206
+        return false;
207
+    }
208
+
209
+    /**
210
+     * Verify with Apache whether user is authenticated.
211
+     *
212
+     * @return boolean|null
213
+     *          true: authenticated
214
+     *          false: not authenticated
215
+     *          null: not handled / no backend available
216
+     */
217
+    public static function handleApacheAuth() {
218
+        $backend = self::findFirstActiveUsedBackend();
219
+        if ($backend) {
220
+            OC_App::loadApps();
221
+
222
+            //setup extra user backends
223
+            self::setupBackends();
224
+            \OC::$server->getUserSession()->unsetMagicInCookie();
225
+
226
+            return self::loginWithApache($backend);
227
+        }
228
+
229
+        return null;
230
+    }
231
+
232
+
233
+    /**
234
+     * Sets user id for session and triggers emit
235
+     *
236
+     * @param string $uid
237
+     */
238
+    public static function setUserId($uid) {
239
+        $userSession = \OC::$server->getUserSession();
240
+        $userManager = \OC::$server->getUserManager();
241
+        if ($user = $userManager->get($uid)) {
242
+            $userSession->setUser($user);
243
+        } else {
244
+            \OC::$server->getSession()->set('user_id', $uid);
245
+        }
246
+    }
247
+
248
+    /**
249
+     * Check if the user is logged in, considers also the HTTP basic credentials
250
+     *
251
+     * @deprecated use \OC::$server->getUserSession()->isLoggedIn()
252
+     * @return bool
253
+     */
254
+    public static function isLoggedIn() {
255
+        return \OC::$server->getUserSession()->isLoggedIn();
256
+    }
257
+
258
+    /**
259
+     * set incognito mode, e.g. if a user wants to open a public link
260
+     *
261
+     * @param bool $status
262
+     */
263
+    public static function setIncognitoMode($status) {
264
+        self::$incognitoMode = $status;
265
+    }
266
+
267
+    /**
268
+     * get incognito mode status
269
+     *
270
+     * @return bool
271
+     */
272
+    public static function isIncognitoMode() {
273
+        return self::$incognitoMode;
274
+    }
275
+
276
+    /**
277
+     * Returns the current logout URL valid for the currently logged-in user
278
+     *
279
+     * @param \OCP\IURLGenerator $urlGenerator
280
+     * @return string
281
+     */
282
+    public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
283
+        $backend = self::findFirstActiveUsedBackend();
284
+        if ($backend) {
285
+            return $backend->getLogoutUrl();
286
+        }
287
+
288
+        $user = \OC::$server->getUserSession()->getUser();
289
+        if ($user instanceof \OCP\IUser) {
290
+            $backend = $user->getBackend();
291
+            if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
292
+                return $backend->getLogoutUrl();
293
+            }
294
+        }
295
+
296
+        $logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
297
+        $logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
298
+
299
+        return $logoutUrl;
300
+    }
301
+
302
+    /**
303
+     * Check if the user is an admin user
304
+     *
305
+     * @param string $uid uid of the admin
306
+     * @return bool
307
+     */
308
+    public static function isAdminUser($uid) {
309
+        $group = \OC::$server->getGroupManager()->get('admin');
310
+        $user = \OC::$server->getUserManager()->get($uid);
311
+        if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
312
+            return true;
313
+        }
314
+        return false;
315
+    }
316
+
317
+
318
+    /**
319
+     * get the user id of the user currently logged in.
320
+     *
321
+     * @return string|bool uid or false
322
+     */
323
+    public static function getUser() {
324
+        $uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null;
325
+        if (!is_null($uid) && self::$incognitoMode === false) {
326
+            return $uid;
327
+        } else {
328
+            return false;
329
+        }
330
+    }
331
+
332
+    /**
333
+     * get the display name of the user currently logged in.
334
+     *
335
+     * @param string $uid
336
+     * @return string|bool uid or false
337
+     * @deprecated 8.1.0 fetch \OCP\IUser (has getDisplayName()) by using method
338
+     *                   get() of \OCP\IUserManager - \OC::$server->getUserManager()
339
+     */
340
+    public static function getDisplayName($uid = null) {
341
+        if ($uid) {
342
+            $user = \OC::$server->getUserManager()->get($uid);
343
+            if ($user) {
344
+                return $user->getDisplayName();
345
+            } else {
346
+                return $uid;
347
+            }
348
+        } else {
349
+            $user = \OC::$server->getUserSession()->getUser();
350
+            if ($user) {
351
+                return $user->getDisplayName();
352
+            } else {
353
+                return false;
354
+            }
355
+        }
356
+    }
357
+
358
+    /**
359
+     * Set password
360
+     *
361
+     * @param string $uid The username
362
+     * @param string $password The new password
363
+     * @param string $recoveryPassword for the encryption app to reset encryption keys
364
+     * @return bool
365
+     *
366
+     * Change the password of a user
367
+     */
368
+    public static function setPassword($uid, $password, $recoveryPassword = null) {
369
+        $user = \OC::$server->getUserManager()->get($uid);
370
+        if ($user) {
371
+            return $user->setPassword($password, $recoveryPassword);
372
+        } else {
373
+            return false;
374
+        }
375
+    }
376
+
377
+    /**
378
+     * @param string $uid The username
379
+     * @return string
380
+     *
381
+     * returns the path to the users home directory
382
+     * @deprecated Use \OC::$server->getUserManager->getHome()
383
+     */
384
+    public static function getHome($uid) {
385
+        $user = \OC::$server->getUserManager()->get($uid);
386
+        if ($user) {
387
+            return $user->getHome();
388
+        } else {
389
+            return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
390
+        }
391
+    }
392
+
393
+    /**
394
+     * Get a list of all users display name
395
+     *
396
+     * @param string $search
397
+     * @param int $limit
398
+     * @param int $offset
399
+     * @return array associative array with all display names (value) and corresponding uids (key)
400
+     *
401
+     * Get a list of all display names and user ids.
402
+     * @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead.
403
+     */
404
+    public static function getDisplayNames($search = '', $limit = null, $offset = null) {
405
+        $displayNames = [];
406
+        $users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset);
407
+        foreach ($users as $user) {
408
+            $displayNames[$user->getUID()] = $user->getDisplayName();
409
+        }
410
+        return $displayNames;
411
+    }
412
+
413
+    /**
414
+     * Returns the first active backend from self::$_usedBackends.
415
+     *
416
+     * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
417
+     */
418
+    private static function findFirstActiveUsedBackend() {
419
+        foreach (self::$_usedBackends as $backend) {
420
+            if ($backend instanceof OCP\Authentication\IApacheBackend) {
421
+                if ($backend->isSessionActive()) {
422
+                    return $backend;
423
+                }
424
+            }
425
+        }
426
+
427
+        return null;
428
+    }
429 429
 }
Please login to merge, or discard this patch.