Documentation

User
in package

Represents a user, logged in or not.

Tags
author

Samerton

author

Partydragen

author

Aberdeener

version
2.2.0
license

MIT

Table of Contents

Properties

$_admSessionName  : string
$_cookieName  : string
$_data  : UserData|null
$_db  : DB
$_group_cache  : array<string|int, mixed>
$_groups  : array<int, Group>
$_integration_cache  : array<string|int, mixed>
$_integrations  : array<string|int, IntegrationUser>
$_isAdmLoggedIn  : bool
$_isLoggedIn  : bool
$_main_group  : Group
$_placeholders  : array<string|int, mixed>
$_sessionName  : string
$_user_cache  : array<string|int, mixed>

Methods

__construct()  : mixed
addGroup()  : bool
Add a group to this user.
adminLogin()  : bool
Handle StaffCP logins.
admLogout()  : void
Process logout if user is admin.
canBypassPrivateProfile()  : bool
Can the user bypass private profiles?
canPrivateProfile()  : bool
Is private profile enabled and does he have the permission to use it?
canViewStaffCP()  : bool
Can the specified user view StaffCP?
checkCredentials()  : bool
Check whether given credentials are valid.
create()  : void
Create a new user.
data()  : UserData
Get the user's data.
emailToId()  : int|null
Return an ID from an email.
exists()  : bool
Does this user exist?
getActiveSessions()  : array<string|int, mixed>
getAllGroupHtml()  : array<string|int, mixed>
Get all of a user's group HTML display code.
getAllGroupIds()  : array<string|int, mixed>
Get all of a user's groups id. Logged out/non-existent users will return just `0`.
getAvatar()  : string
Get this user's avatar.
getDisplayname()  : string
Get user's display name.
getForumPlaceholders()  : array<string|int, mixed>
Get this user's placeholders to display on their forum posts.
getGroups()  : array<int, Group>
Get the user's groups.
getGroupStyle()  : string
Get this user's main group CSS styling.
getIntegration()  : IntegrationUser|null
Get the user's integration.
getIntegrations()  : array<string|int, IntegrationUser>
Get the user's integrations.
getMainGroup()  : Group
Get this user's main group (with highest order).
getNotificationPreferences()  : UserNotificationData|array<string|int, UserNotificationData>|null
Get user's notification preferences.
getPlaceholders()  : array<string|int, mixed>
Get the users placeholders.
getPM()  : array<string|int, mixed>|null
Get a specific private message, and see if the user actually has permission to view it.
getProfileFields()  : array<int, UserProfileField>
Get profile fields for this user.
getProfilePlaceholders()  : array<string|int, mixed>
Get this user's placeholders to display on their profile.
getProfileURL()  : string
Build this user's profile link.
getProfileViews()  : int
Get this user's profile views.
getSignature()  : string
Get this user's signature.
getUserTemplates()  : array<string|int, mixed>
Get templates this user's group has access to.
handlePanelPageLoad()  : bool
Check the user's permission to see if they can view this staffCP page or not.
hasPermission()  : bool
Does the user have a specific permission in any of their groups?
idToName()  : string|null
Get a user's username from their ID.
idToNickname()  : string|null
Get a user's nickname from their ID.
isAdmLoggedIn()  : bool
Get if the current user is authenticated as an administrator.
isBlocked()  : bool
Is a user blocked?
isLoggedIn()  : bool
Get if this user is currently logged in or not.
isPrivateProfile()  : bool
Is the profile page set to private?
isValidated()  : bool
Get if this user is active/validated or not.
listAllOtherUsers()  : array<string|int, mixed>
Get a comma separated string of all other users who have not blocked this user.
listPMs()  : array<string|int, mixed>
Get a list of PMs a user has access to.
login()  : bool
Log the user in.
logout()  : void
Log the user out.
logoutAllOtherSessions()  : void
Log the user out from all other sessions.
logoutSessionById()  : void
Log the user out from a selected session.
nameToId()  : int|null
Return an ID from a username.
removeGroup()  : bool
Remove a group from the user.
savePlaceholders()  : void
Save/update this user's placeholders.
setGroup()  : false|void
Set a group to user and remove all other groups.
update()  : void
Update a user's data in the database.
_commonLogin()  : bool
find()  : bool
Find a user by unique identifier (username, ID, email, etc).

Properties

$_admSessionName

private string $_admSessionName

The session name configuration value for remembering the admin user.

$_cookieName

private string $_cookieName

The cookie name configuration value.

$_data

private UserData|null $_data

The user's data. Basically just the row from nl2_users where the user ID is the key.

$_group_cache

private static array<string|int, mixed> $_group_cache = []

$_groups

private array<int, Group> $_groups

The user's groups.

$_integration_cache

private static array<string|int, mixed> $_integration_cache = []

$_isAdmLoggedIn

private bool $_isAdmLoggedIn = \false

Whether this user is logged in as an admin or not.

$_isLoggedIn

private bool $_isLoggedIn = \false

Whether this user is logged in or not.

$_main_group

private Group $_main_group

The user's main group.

$_placeholders

private array<string|int, mixed> $_placeholders

The user's placeholders.

$_sessionName

private string $_sessionName

The session name configuration value for remembering the user.

$_user_cache

private static array<string|int, mixed> $_user_cache = []

Methods

__construct()

public __construct([string|null $user = null ][, string $field = 'id' ]) : mixed
Parameters
$user : string|null = null
$field : string = 'id'

addGroup()

Add a group to this user.

public addGroup(int $group_id[, int $expire = 0 ]) : bool
Parameters
$group_id : int

ID of group to give.

$expire : int = 0

Expiry in epoch time. If not supplied, group will never expire.

Return values
bool —

True on success, false if they already have it.

adminLogin()

Handle StaffCP logins.

public adminLogin([string|null $username = null ][, string|null $password = null ][, string $method = 'email' ]) : bool
Parameters
$username : string|null = null

Their username (or email, depending on $method).

$password : string|null = null

Their password.

$method : string = 'email'

What column to check for their details in. Can be either username or email.

Return values
bool —

True/false on success or failure respectfully.

admLogout()

Process logout if user is admin.

public admLogout() : void

canBypassPrivateProfile()

Can the user bypass private profiles?

public canBypassPrivateProfile() : bool
Return values
bool —

Whether the user can bypass private profiles

canPrivateProfile()

Is private profile enabled and does he have the permission to use it?

public canPrivateProfile() : bool
Return values
bool —

Whether profile privatizing is allowed and if they have permission to use it.

canViewStaffCP()

Can the specified user view StaffCP?

public canViewStaffCP() : bool
Return values
bool —

Whether they can view it or not.

checkCredentials()

Check whether given credentials are valid.

public checkCredentials(string $username, string $password[, string $method = 'email' ]) : bool
Parameters
$username : string

Username (or email) to check.

$password : string

Password entered by user.

$method : string = 'email'

Column to search for user with. Can be email or username or oauth. If it is oauth, then the request will be granted.

Return values
bool —

True if correct, false otherwise.

create()

Create a new user.

public create([array<string|int, mixed> $fields = [] ]) : void
Parameters
$fields : array<string|int, mixed> = []

Column names and values to insert to database.

emailToId()

Return an ID from an email.

public emailToId(string $email) : int|null
Parameters
$email : string

Email to get ID for.

Return values
int|null —

ID on success, false on failure.

exists()

Does this user exist?

public exists() : bool
Return values
bool —

Whether the user exists (has data) or not.

getActiveSessions()

public getActiveSessions() : array<string|int, mixed>
Return values
array<string|int, mixed>

getAllGroupHtml()

Get all of a user's group HTML display code.

public getAllGroupHtml() : array<string|int, mixed>
Return values
array<string|int, mixed> —

Array of all their groups HTML.

getAllGroupIds()

Get all of a user's groups id. Logged out/non-existent users will return just `0`.

public getAllGroupIds() : array<string|int, mixed>
Return values
array<string|int, mixed> —

Array of all their group IDs.

getAvatar()

Get this user's avatar.

public getAvatar([int $size = 128 ][, bool $full = false ]) : string
Parameters
$size : int = 128

Size of image to render in pixels.

$full : bool = false

Whether to use full site URL or not, for external loading - ie discord webhooks.

Return values
string —

URL to their avatar image.

getDisplayname()

Get user's display name.

public getDisplayname([bool $username = false ]) : string
Parameters
$username : bool = false

If true, will use their username. If false, will use their nickname.

Return values
string —

Their display name.

getForumPlaceholders()

Get this user's placeholders to display on their forum posts.

public getForumPlaceholders() : array<string|int, mixed>
Return values
array<string|int, mixed> —

Forum placeholders.

getGroups()

Get the user's groups.

public getGroups() : array<int, Group>
Return values
array<int, Group> —

Their groups.

getGroupStyle()

Get this user's main group CSS styling.

public getGroupStyle() : string
Return values
string —

The CSS styling.

getIntegration()

Get the user's integration.

public getIntegration(string $integrationName) : IntegrationUser|null
Parameters
$integrationName : string

Integration name

Return values
IntegrationUser|null —

Their integration user if connected otherwise null.

getIntegrations()

Get the user's integrations.

public getIntegrations() : array<string|int, IntegrationUser>
Return values
array<string|int, IntegrationUser> —

Their integrations.

getMainGroup()

Get this user's main group (with highest order).

public getMainGroup() : Group
Return values
Group —

The group

getPlaceholders()

Get the users placeholders.

public getPlaceholders() : array<string|int, mixed>
Return values
array<string|int, mixed> —

Their placeholders.

getPM()

Get a specific private message, and see if the user actually has permission to view it.

public getPM(int $pm_id, int $user_id) : array<string|int, mixed>|null
Parameters
$pm_id : int

ID of PM to find.

$user_id : int

ID of user to check permission for.

Return values
array<string|int, mixed>|null —

Array of info about PM, null on failure.

getProfileFields()

Get profile fields for this user.

public getProfileFields([bool $show_private = false ][, bool $only_forum = false ]) : array<int, UserProfileField>
Parameters
$show_private : bool = false

Whether to only return public fields or not (default true).

$only_forum : bool = false

Whether to only return fields which display on forum posts, only if $public is true (default false).

Return values
array<int, UserProfileField> —

Array of profile fields.

getProfilePlaceholders()

Get this user's placeholders to display on their profile.

public getProfilePlaceholders() : array<string|int, mixed>
Return values
array<string|int, mixed> —

Profile placeholders.

getProfileURL()

Build this user's profile link.

public getProfileURL() : string
Return values
string —

Compiled profile URL.

getProfileViews()

Get this user's profile views.

public getProfileViews() : int
Return values
int —

Numer of profile views they have

getSignature()

Get this user's signature.

public getSignature() : string
Return values
string —

Their signature.

getUserTemplates()

Get templates this user's group has access to.

public getUserTemplates() : array<string|int, mixed>
Return values
array<string|int, mixed> —

Templates which the user has access to.

handlePanelPageLoad()

Check the user's permission to see if they can view this staffCP page or not.

public handlePanelPageLoad([string|null $permission = null ]) : bool

If they cannot, this will handle appropriate redirection.

Parameters
$permission : string|null = null

Permission required for this page.

Return values
bool

hasPermission()

Does the user have a specific permission in any of their groups?

public hasPermission(string $permission) : bool
Parameters
$permission : string

Permission node to check recursively for.

Return values
bool —

Whether they inherit this permission or not.

idToName()

Get a user's username from their ID.

public idToName(int $id) : string|null
Parameters
$id : int

Their ID.

Return values
string|null —

Their username, null on failure.

idToNickname()

Get a user's nickname from their ID.

public idToNickname(int $id) : string|null
Parameters
$id : int

Their ID.

Return values
string|null —

Their nickname, null on failure.

isAdmLoggedIn()

Get if the current user is authenticated as an administrator.

public isAdmLoggedIn() : bool
Return values
bool —

Whether they're logged in as admin.

isBlocked()

Is a user blocked?

public isBlocked(int $user, int $blocked) : bool
Parameters
$user : int

ID of first user

$blocked : int

ID of user who may or may not be blocked

Return values
bool —

Whether they are blocked or not.

isLoggedIn()

Get if this user is currently logged in or not.

public isLoggedIn() : bool
Return values
bool —

Whether they're logged in.

isPrivateProfile()

Is the profile page set to private?

public isPrivateProfile() : bool
Return values
bool —

Whether their profile is set to private or not.

isValidated()

Get if this user is active/validated or not.

public isValidated() : bool
Return values
bool —

Whether this user has been validated/activated.

listAllOtherUsers()

Get a comma separated string of all other users who have not blocked this user.

public listAllOtherUsers() : array<string|int, mixed>

For the new private message dropdown.

Return values
array<string|int, mixed> —

Array of usernames.

listPMs()

Get a list of PMs a user has access to.

public listPMs(int $user_id) : array<string|int, mixed>
Parameters
$user_id : int

ID of user to get PMs for.

Return values
array<string|int, mixed> —

Array of PMs.

login()

Log the user in.

public login([string|null $username = null ][, string|null $password = null ][, bool $remember = false ][, string $method = 'email' ]) : bool
Parameters
$username : string|null = null

Their username (or email, depending on $method).

$password : string|null = null

Their password.

$remember : bool = false

Whether to keep them logged in or not.

$method : string = 'email'

What column to check for their details in. Can be either username or email or oauth.

Return values
bool —

True/false on success or failure respectfully.

logout()

Log the user out.

public logout() : void

Deletes their cookies, sessions and database session entry.

logoutAllOtherSessions()

Log the user out from all other sessions.

public logoutAllOtherSessions() : void

logoutSessionById()

Log the user out from a selected session.

public logoutSessionById(string $sessionId) : void
Parameters
$sessionId : string

Selected session ID.

nameToId()

Return an ID from a username.

public nameToId(string $username) : int|null
Parameters
$username : string

Username to get ID for.

Return values
int|null —

ID on success, null on failure.

removeGroup()

Remove a group from the user.

public removeGroup(int|null $group_id) : bool
Parameters
$group_id : int|null

ID of group to remove.

Return values
bool —

Returns false if they did not have this group or the admin group is being removed from root user

savePlaceholders()

Save/update this user's placeholders.

public savePlaceholders(int $server_id, array<string|int, mixed> $placeholders) : void
Parameters
$server_id : int

Server ID from staffcp -> integrations to assoc these placeholders with.

$placeholders : array<string|int, mixed>

Key/value array of placeholders name/value from API endpoint.

setGroup()

Set a group to user and remove all other groups.

public setGroup(int $group_id[, int $expire = 0 ]) : false|void
Parameters
$group_id : int

ID of group to set as main group.

$expire : int = 0

Expiry in epoch time. If not supplied, group will never expire.

Return values
false|void

update()

Update a user's data in the database.

public update([array<string|int, mixed> $fields = [] ]) : void
Parameters
$fields : array<string|int, mixed> = []

Column names and values to update.

Tags
throws
Exception

_commonLogin()

private _commonLogin(string|null $username, string|null $password, bool $remember, string $method, bool $is_admin) : bool
Parameters
$username : string|null
$password : string|null
$remember : bool
$method : string
$is_admin : bool
Return values
bool

find()

Find a user by unique identifier (username, ID, email, etc).

private find(string $value[, string $field = 'id' ]) : bool

Loads instance variables for this class.

Parameters
$value : string

Unique identifier.

$field : string = 'id'

What column to check for their unique identifier in.

Return values
bool —

True/false on success or failure respectfully.


        
On this page

Search results