Skip to content

Commit f791d91

Browse files
Merge pull request #57224 from nextcloud/jtr/docs-iusersession
docs(IUserSession): Improve interface docs
2 parents 6acf2a6 + fc37abd commit f791d91

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

lib/public/IUserSession.php

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,94 @@
11
<?php
22

33
/**
4-
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
4+
* SPDX-FileCopyrightText: 2016-2025 Nextcloud GmbH and Nextcloud contributors
55
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66
* SPDX-License-Identifier: AGPL-3.0-only
77
*/
8-
// use OCP namespace for all classes that are considered public.
9-
// This means that they should be used by apps instead of the internal Nextcloud classes
108

119
namespace OCP;
1210

1311
/**
14-
* User session
12+
* Interface for managing and querying user session state.
13+
*
14+
* Provides methods for authenticating users, accessing the active user,
15+
* and handling login/logout functionality in a Nextcloud server session.
1516
* @since 6.0.0
1617
*/
1718
interface IUserSession {
1819
/**
19-
* Do a user login
20+
* Attempts to authenticate the given user and start a session.
2021
*
21-
* @param string $uid the username
22-
* @param string $password the password
23-
* @return bool true if successful
22+
* @param string $uid The user's unique identifier (username).
23+
* @param string $password The user's plain-text password.
24+
* @return bool True on successful login, false otherwise.
2425
* @since 6.0.0
2526
*/
2627
public function login($uid, $password);
2728

2829
/**
29-
* Logs the user out including all the session data
30-
* Logout, destroys session
30+
* Logs out the current user and terminates their session.
31+
*
32+
* Clears authentication tokens and user-related session data.
3133
*
3234
* @return void
3335
* @since 6.0.0
3436
*/
3537
public function logout();
3638

3739
/**
38-
* set the currently active user
40+
* Sets the current active user for this session.
41+
*
42+
* Pass null to clear the active user and log out any existing session.
3943
*
40-
* @param \OCP\IUser|null $user
44+
* @param \OCP\IUser|null $user The user to set as active, or null to unset.
4145
* @since 8.0.0
4246
*/
4347
public function setUser($user);
4448

4549
/**
46-
* Temporarily set the currently active user without persisting in the session
50+
* Temporarily sets the active user for this session without persisting it in the session storage.
51+
*
52+
* Useful for request-scoped user overrides that do not affect the actual session state.
4753
*
48-
* @param IUser|null $user
54+
* @param \OCP\IUser|null $user The user to set as active, or null to clear.
4955
* @since 29.0.0
5056
*/
5157
public function setVolatileActiveUser(?IUser $user): void;
5258

5359
/**
54-
* get the current active user
60+
* Returns the currently authenticated user for this session, or null if the session has no active user.
5561
*
56-
* @return \OCP\IUser|null Current user, otherwise null
62+
* @return \OCP\IUser|null The active user, or null if the session is anonymous, expired, or in incognito mode.
5763
* @since 8.0.0
5864
*/
5965
public function getUser();
6066

6167
/**
62-
* Checks whether the user is logged in
68+
* Checks whether a user is currently logged in for this session.
6369
*
64-
* @return bool if logged in
70+
* @return bool True if a user is authenticated and enabled, false otherwise.
6571
* @since 8.0.0
6672
*/
6773
public function isLoggedIn();
6874

6975
/**
70-
* get getImpersonatingUserID
76+
* Returns the user ID of the impersonator if another user is being impersonated.
7177
*
72-
* @return string|null
78+
* @return string|null The impersonating user's ID, or null if not impersonating.
7379
* @since 18.0.0
7480
*/
7581
public function getImpersonatingUserID(): ?string;
7682

7783
/**
78-
* set setImpersonatingUserID
84+
* Sets or clears the impersonator's user ID in the current session.
85+
*
86+
* Note: This does not initiate impersonation, but only records the identity of the impersonator in the session.
87+
*
88+
* If $useCurrentUser is true (default), records the current user's ID as the impersonator.
89+
* If false, removes any impersonator information from the session.
7990
*
91+
* @param bool $useCurrentUser Whether to assign the current user as the impersonator or to clear it.
8092
* @since 18.0.0
8193
*/
8294
public function setImpersonatingUserID(bool $useCurrentUser = true): void;

0 commit comments

Comments
 (0)