IUserSession
in
Interface for managing and querying user session state.
Provides methods for authenticating users, accessing the active user, and handling login/logout functionality in a Nextcloud server session.
Tags
Table of Contents
Methods
- getImpersonatingUserID() : string|null
- Returns the user ID of the impersonator if another user is being impersonated.
- getUser() : IUser|null
- Returns the currently authenticated user for this session, or null if the session has no active user.
- isLoggedIn() : bool
- Checks whether a user is currently logged in for this session.
- login() : bool
- Attempts to authenticate the given user and start a session.
- logout() : void
- Logs out the current user and terminates their session.
- setImpersonatingUserID() : void
- Sets or clears the impersonator's user ID in the current session.
- setUser() : mixed
- Sets the current active user for this session.
- setVolatileActiveUser() : void
- Temporarily sets the active user for this session without persisting it in the session storage.
Methods
getImpersonatingUserID()
Returns the user ID of the impersonator if another user is being impersonated.
public
getImpersonatingUserID() : string|null
Tags
Return values
string|null —The impersonating user's ID, or null if not impersonating.
getUser()
Returns the currently authenticated user for this session, or null if the session has no active user.
public
getUser() : IUser|null
Tags
Return values
IUser|null —The active user, or null if the session is anonymous, expired, or in incognito mode.
isLoggedIn()
Checks whether a user is currently logged in for this session.
public
isLoggedIn() : bool
Tags
Return values
bool —True if a user is authenticated and enabled, false otherwise.
login()
Attempts to authenticate the given user and start a session.
public
login(string $uid, string $password) : bool
Parameters
- $uid : string
-
The user's unique identifier (username).
- $password : string
-
The user's plain-text password.
Tags
Return values
bool —True on successful login, false otherwise.
logout()
Logs out the current user and terminates their session.
public
logout() : void
Clears authentication tokens and user-related session data.
Tags
setImpersonatingUserID()
Sets or clears the impersonator's user ID in the current session.
public
setImpersonatingUserID([bool $useCurrentUser = true ]) : void
Note: This does not initiate impersonation, but only records the identity of the impersonator in the session.
If $useCurrentUser is true (default), records the current user's ID as the impersonator. If false, removes any impersonator information from the session.
Parameters
- $useCurrentUser : bool = true
-
Whether to assign the current user as the impersonator or to clear it.
Tags
setUser()
Sets the current active user for this session.
public
setUser(IUser|null $user) : mixed
Pass null to clear the active user and log out any existing session.
Parameters
- $user : IUser|null
-
The user to set as active, or null to unset.
Tags
setVolatileActiveUser()
Temporarily sets the active user for this session without persisting it in the session storage.
public
setVolatileActiveUser(IUser|null $user) : void
Useful for request-scoped user overrides that do not affect the actual session state.
Parameters
- $user : IUser|null
-
The user to set as active, or null to clear.