Nextcloud PHP API (master)

IUserManager

Class Manager

Hooks available in scope \OC\User:

  • preSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
  • postSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
  • preDelete(\OC\User\User $user)
  • postDelete(\OC\User\User $user)
  • preCreateUser(string $uid, string $password)
  • postCreateUser(\OC\User\User $user, string $password)
  • assignedUserId(string $uid)
  • preUnassignedUserId(string $uid)
  • postUnassignedUserId(string $uid)
Tags
since
8.0.0

Table of Contents

Constants

MAX_PASSWORD_LENGTH  = 469

Methods

callForAllUsers()  : mixed
callForSeenUsers()  : mixed
checkPassword()  : IUser|false
Check if the password is valid for the user
clearBackends()  : void
remove all user backends
countDisabledUsers()  : int
returns how many users have logged in once
countSeenUsers()  : int
returns how many users have logged in once
countUsers()  : array<string, int>
Get how many users per backend exist (if supported by backend)
countUsersTotal()  : int|false
Get how many users exists in total, whithin limit
createUser()  : false|IUser
createUserFromBackend()  : IUser|null
get()  : IUser|null
get a user by user id
getBackends()  : array<string|int, UserInterface>
Get the active backends
getByEmail()  : array<string|int, IUser>
returns all users having the provided email set as system email address
getDisabledUsers()  : array<string|int, IUser>
getDisplayName()  : string|null
Get the display name of a user
getExistingUser()  : IUser
Get a user by user id without validating that the user exists.
getLastLoggedInUsers()  : array<int, string>
Gets the list of users sorted by lastLogin, from most recent to least recent
getSeenUsers()  : Iterator<string, IUser>
Gets the list of users.
registerBackend()  : void
register a user backend
removeBackend()  : void
remove a user backend
search()  : array<string|int, IUser>
search by user id
searchDisplayName()  : array<int, IUser>
search by displayName
searchKnownUsersByDisplayName()  : array<string|int, IUser>
Search known users (from phonebook sync) by displayName
userExists()  : bool
check if a user exists
validateUserId()  : void

Constants

MAX_PASSWORD_LENGTH

public mixed MAX_PASSWORD_LENGTH = 469
Tags
since
26.0.0

Methods

callForAllUsers()

public callForAllUsers(Closure $callback[, string $search = '' ]) : mixed
Parameters
$callback : Closure
$search : string = ''
Tags
psalm-param

\Closure(\OCP\IUser):void $callback

since
9.0.0

callForSeenUsers()

public callForSeenUsers(Closure $callback) : mixed
Parameters
$callback : Closure
Tags
psalm-param

\Closure(\OCP\IUser):?bool $callback

since
11.0.0

checkPassword()

Check if the password is valid for the user

public checkPassword(string $loginName, string $password) : IUser|false
Parameters
$loginName : string
$password : string
Tags
since
8.0.0
Return values
IUser|false

the User object on success, false otherwise

clearBackends()

remove all user backends

public clearBackends() : void
Tags
since
8.0.0

countDisabledUsers()

returns how many users have logged in once

public countDisabledUsers() : int
Tags
since
11.0.0
Return values
int

countSeenUsers()

returns how many users have logged in once

public countSeenUsers() : int
Tags
since
11.0.0
Return values
int

countUsers()

Get how many users per backend exist (if supported by backend)

public countUsers([bool $onlyMappedUsers = false ]) : array<string, int>
Parameters
$onlyMappedUsers : bool = false
Tags
since
8.0.0
since
33.0.0

$onlyMappedUsers parameter

Return values
array<string, int>

an array of backend class name as key and count number as value

countUsersTotal()

Get how many users exists in total, whithin limit

public countUsersTotal([int $limit = 0 ][, bool $onlyMappedUsers = false ]) : int|false
Parameters
$limit : int = 0

Limit the count to avoid resource waste. 0 to disable

$onlyMappedUsers : bool = false

Count mapped users instead of all users for compatible backends

Tags
since
31.0.0
Return values
int|false

createUser()

public createUser(string $uid, string $password) : false|IUser
Parameters
$uid : string
$password : string
Tags
throws
InvalidArgumentException
since
8.0.0
Return values
false|IUser

the created user or false

createUserFromBackend()

public createUserFromBackend(string $uid, string $password, UserInterface $backend) : IUser|null
Parameters
$uid : string
$password : string
$backend : UserInterface
Tags
throws
InvalidArgumentException
since
12.0.0
Return values
IUser|null

get()

get a user by user id

public get(string $uid) : IUser|null

If you're already 100% sure that the user exists, consider IUserManager::getExistingUser which has less overhead.

Parameters
$uid : string
Tags
since
8.0.0
Return values
IUser|null

Either the user or null if the specified user does not exist

getByEmail()

returns all users having the provided email set as system email address

public getByEmail(string $email) : array<string|int, IUser>
Parameters
$email : string
Tags
since
9.1.0
Return values
array<string|int, IUser>

getDisabledUsers()

public getDisabledUsers([int|null $limit = null ][, int $offset = 0 ][, string $search = '' ]) : array<string|int, IUser>
Parameters
$limit : int|null = null
$offset : int = 0
$search : string = ''
Tags
since
28.0.0
since
30.0.0

$search parameter added

Return values
array<string|int, IUser>

getDisplayName()

Get the display name of a user

public getDisplayName(string $uid) : string|null
Parameters
$uid : string
Tags
since
25.0.0
Return values
string|null

getExistingUser()

Get a user by user id without validating that the user exists.

public getExistingUser(string $userId[, string|null $displayName = null ]) : IUser

This should only be used if you're certain that the provided user id exists in the system. Using this to get a user object for a non-existing user will lead to unexpected behavior down the line.

If you're not 100% sure that the user exists, use IUserManager::get instead.

Parameters
$userId : string
$displayName : string|null = null

If the display name is known in advance you can provide it so it doesn't have to be fetched again

Tags
since
33.0.0
Return values
IUser

getLastLoggedInUsers()

Gets the list of users sorted by lastLogin, from most recent to least recent

public getLastLoggedInUsers([int|null $limit = null ][, int $offset = 0 ][, string $search = '' ]) : array<int, string>
Parameters
$limit : int|null = null

how many records to fetch

$offset : int = 0

from which offset to fetch

$search : string = ''

search users based on search params

Tags
since
30.0.0
Return values
array<int, string>

list of user IDs

getSeenUsers()

Gets the list of users.

public getSeenUsers([int $offset = 0 ][, int|null $limit = null ]) : Iterator<string, IUser>

An iterator is returned allowing the caller to stop the iteration at any time. The offset argument allows the caller to continue the iteration at a specific offset.

Parameters
$offset : int = 0

from which offset to fetch

$limit : int|null = null

maximum number of records to fetch

Tags
since
33.0.0

users are yielded with the user id as key

since
32.0.0
Return values
Iterator<string, IUser>

list of IUser object

search by user id

public search(string $pattern[, int $limit = null ][, int $offset = null ]) : array<string|int, IUser>

use searchDisplayName instead

Parameters
$pattern : string
$limit : int = null
$offset : int = null
Tags
since
8.0.0
Return values
array<string|int, IUser>

searchDisplayName()

search by displayName

public searchDisplayName(string $pattern[, int $limit = null ][, int $offset = null ]) : array<int, IUser>
Parameters
$pattern : string
$limit : int = null
$offset : int = null
Tags
since
8.0.0
Return values
array<int, IUser>

searchKnownUsersByDisplayName()

Search known users (from phonebook sync) by displayName

public searchKnownUsersByDisplayName(string $searcher, string $pattern[, int|null $limit = null ][, int|null $offset = null ]) : array<string|int, IUser>
Parameters
$searcher : string
$pattern : string
$limit : int|null = null
$offset : int|null = null
Tags
since
21.0.1
Return values
array<string|int, IUser>

userExists()

check if a user exists

public userExists(string $uid) : bool
Parameters
$uid : string
Tags
since
8.0.0
Return values
bool

validateUserId()

public validateUserId(string $uid[, bool $checkDataDirectory = false ]) : void
Parameters
$uid : string

The user ID to validate

$checkDataDirectory : bool = false

Whether it should be checked if files for the ID exist inside the data directory

Tags
throws
InvalidArgumentException

Message is an already translated string with a reason why the ID is not valid

since
26.0.0

        
On this page

Search results