class Account extends AuthEntity

Class representing a user account in the database

Can inherit properties from groups. Can have any number of registered clients, can have registered two factor, can provide secret-key crypto services, provides contact info

Traits

Trait that overrides some BaseObject functions to allow inheriting properties from Groups

Constants

IDLength

The length of the ID used to identify the object

DISABLE_PERMANENT

DISABLE_PENDING_CONTACT

DEFAULT_SEARCH_MAX

OBJECT_FULL

OBJECT_ADMIN

Properties

protected $database

The object's primary reference to the database

from  BaseObject
protected Scalar> $scalars from  BaseObject
protected ObjectRef> $objects from  BaseObject
protected ObjectRefs> $objectrefs from  BaseObject
private $modified

whether or not this object has been modified

from  BaseObject
private $deleted

whether or not this object has been deleted

from  BaseObject
private $dbDeleted

whether or not this object has been deleted by DB

from  BaseObject
private $deleteLater from  BaseObject
private $created

True if this object has been created and not yet saved to DB

from  BaseObject
static private $group_handlers
static private $delete_handlers
private $cryptoAvailable
static private $crypto_handlers

Methods

static array
GetFieldTemplate()

Gets a template array of the object's properties (columns).

static string
GetDBClass()

Returns the name of the class that should be used in the database for the table name (cast down at save)

static string
GetObjClass(array $row)

No description

static int
CountByQuery(ObjectDatabase $database, QueryBuilder $query)

Counts objects in the DB matching the given query

static array
LoadByQuery(ObjectDatabase $database, QueryBuilder $query)

Loads an array of objects from the DB matching the given query

static int
DeleteByQuery(ObjectDatabase $database, QueryBuilder $query)

Deletes objects from the DB matching the given query

static BaseObject|null
TryLoadUniqueByQuery(ObjectDatabase $database, QueryBuilder $query)

Loads a unique object matching the given query

static BaseObject
NotNull(BaseObject|null $obj)

Asserts that the given object is not null

static BaseObject|null
TryLoadByID(ObjectDatabase $database, string $id)

Loads a unique object by its ID

static void
DeleteByID(ObjectDatabase $database, string $id)

Deletes a unique object by its ID

static array
LoadAll(ObjectDatabase $database, int|null $limit = null, int|null $offset = null)

Loads all objects of this type from the database

static int
DeleteAll(ObjectDatabase $database)

Deletes all objects of this type from the database

static array
LoadByObjectID(ObjectDatabase $database, string $field, string $id, string|null $class = null)

Loads objects from the database with the given object ID as the value of the given field

static int
DeleteByObjectID(ObjectDatabase $database, string $field, string $id, string|null $class = null)

Deletes objects from the database with the given object ID as the value of the given field

static BaseObject|null
TryLoadUniqueByKey(ObjectDatabase $database, string $field, string $key)

Loads a unique object matching the given field

static bool
TryDeleteByUniqueKey(ObjectDatabase $database, string $field, string $key)

Deletes a unique object matching the given field

static array
LoadByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Loads objects from the database with the given object referenced by the given field

static int
DeleteByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Deletes objects from the database with the given object referenced by the given field

static BaseObject|null
TryLoadUniqueByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Loads a unique object from the database with the given object referenced by the given field

static bool
TryDeleteByUniqueObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Deletes a unique object from the database with the given object referenced by the given field

string
ID()

Returns the unique ID of the object

string
__toString()

Returns the string "id:class" where id is the object ID and class is its short class name

static string|null
toString(BaseObject|null $obj)

Returns the given object's as a string if not null, else null

GetScalar(string $field, bool $allowTemp = true)

No description

TryGetScalar(string $field, bool $allowTemp = true)

No description

int
GetScalarDelta(string $field)

Returns the delta of the given scalar (non-zero if modified)

GetObject(string $field)

No description

BaseObject|null
TryGetObject(string $field)

No description

bool
HasObject(string $field)

Checks if the object reference is not-null without actually loading it (faster)

string
GetObjectID(string $field)

Gets the ID of a referenced object without actually loading it (faster)

string|null
TryGetObjectID(string $field)

Same as GetObjectID() but returns null instead of throwing exceptions

string
GetObjectType(string $field)

Gets the class name of a referenced object without actually loading it (faster)

string|null
TryGetObjectType(string $field)

Gets the class name of a referenced object without actually loading it (faster)

DeleteObject(string $field)

Deletes the object referenced in the field

array
GetObjectRefs(string $field, int|null $limit = null, int|null $offset = null)

Gets an array of objects that reference this object

int
CountObjectRefs(string $field)

Gets the counter of objects referencing this object

GetJoinObject(string $field, BaseObject $obj)

Loads the object that joins together two classes using a FieldTypes\ObjectJoin

StandardObject|null
TryGetJoinObject(string $field, BaseObject $obj)

Same as GetJoinObject() but returns null instead of throwing exceptions

DeleteObjects(string $field)

Deletes all objects that reference this object

SetScalar(string $field, mixed $value, bool $temp = false)

Sets a scalar field to the given value

DeltaCounter(string $name, int $delta = 1, bool $ignoreLimit = false)

Increment a counter by the given value

bool
BoolSetObject(string $field, BaseObject|null $object, bool $notification = false)

Sets a field to reference the given object

SetObject(string $field, BaseObject|null $object, bool $notification = false)

Same as BoolSetObject() but returns $this

bool
AddObjectRef(string $field, BaseObject $object, bool $notification = false)

Adds an object reference, checking for a limit on the number of references

bool
RemoveObjectRef(string $field, BaseObject $object, bool $notification = false)

Removes the given object from a collection of referenced objects

__construct(ObjectDatabase $database, array $data)

Constructs the object by initializing its field template with values from the database

AddField(string $key, Scalar $field)

Adds the given field object to the correct internal array

void
SubConstruct()

Function to allow subclasses to do something after being constructed without overriding the constructor

Save(bool $onlyMandatory = false)

Collects fields that have changed and saves them to the database

bool
isDeleted()

whether or not this object has been, or should be considered, deleted

void
NotifyDBDeleted()

Deletes this object without sending to the DB

void
Delete()

Deletes this account and all associated objects

void
DeleteLater()

Schedules the object to be deleted when Save() is called

bool
isCreated()

True if this object has been created and not yet saved to DB (should not be overriden)

static BaseObject
BaseCreate(ObjectDatabase $database)

Create the object by setting its created date

float
GetDate(string $name)

Returns the timestamp value stored in the given date field

float|null
TryGetDate(string $name)

Returns the timestamp value stored in the given date field

SetDate(string $name, float|null $value = null)

Sets the value of the given date field to the given value

float
GetDateCreated()

Returns the timestamp when this object was created

int
GetFeatureInt(string $name, bool $allowTemp = true)

Gets the value of the given feature field as an int (used for config)

int|null
TryGetFeatureInt(string $name, bool $allowTemp = true)

Gets the value of the given feature field as an int (used for config)

bool
GetFeatureBool(string $name, bool $allowTemp = true)

Gets the value of the given feature field as a bool (used for config)

bool|null
TryGetFeatureBool(string $name, bool $allowTemp = true)

Gets the value of the given feature field as a bool (used for config)

SetFeatureInt(string $name, int|null $value, bool $temp = false)

Sets the value of the given feature field to the given (?int) value

SetFeatureBool(string $name, bool|null $value, bool $temp = false)

Sets the value of the given feature field to the given (?bool) value

bool
isFeatureModified(string $name)

Returns true if the given feature has been modified

int
GetCounter(string $name)

Gets the value of the given counter field

int
GetCounterLimit(string $name)

Gets the value of the given counter limit field

int|null
TryGetCounterLimit(string $name)

Gets the value of the given counter limit field

SetCounterLimit(string $name, int|null $value, bool $temp = false)

Sets the value of the given counter limit field

bool
CheckCounter(string $name, int $delta = 0, bool $except = true)

Checks whether the given counter plus a delta would exceed the limit

array
GetAllScalars(string|null $prefix)

Gets an array of the values of all fields matching a prefix

string
GetDisplayName()

Returns the account's full name if set, else its username

array
GetContacts(bool $valid = true)

Returns all contacts for this account

void
SendMessage(string $subject, string|null $html, string $plain, Account|null $from = null)

Sends a message to all of this account's valid contacts

static string
GetPropUsage()

defines command usage for SetProperties()

SetProperties(Input $input)

Sets the value of an inherited property for the object

BaseObject|null
TryGetInheritsScalarFrom(string $field)

Returns the object that the value of the given field is inherited from

BaseObject|null
TryGetInheritsObjectFrom(string $field)

Returns the object that the value of the given field is inherited from

TryGetInheritable(string $field, bool $useobj = false)

Returns an inherited property value and source pair

static array
GetInheritedFields()

Gets the fields that can be inherited from a group, with their default values

string
GetUsername()

Returns the account's username

SetFullName(string $data)

Sets the account's full name

array
GetDefaultGroups()

Loads the groups that the account implicitly belongs to

array
GetGroups()

Returns a list of all groups that the account belongs to

array
GetMyGroups()

Returns a list of all groups that the account explicitly belongs to

AddGroup(Group $group)

Adds the account to the given group

RemoveGroup(Group $group)

Removes the account from the given group

bool
HasGroup(Group $group)

Returns true if the account is a member of the given group

static 
RegisterGroupChangeHandler(callable $func)

Registers a function to be run when the account is added to or removed from a group

static 
RunGroupChangeHandlers(ObjectDatabase $database, Account $account, Group $group, bool $added)

Runs all functions registered to handle the account being added to or removed from a group

GroupJoin|null
GetGroupJoin(Group $group)

Returns the object joining this account to the given group

GetAuthSource()

Returns the auth source the account authenticates against

array
GetClients()

Returns an array of clients registered to the account

DeleteClients()

Deletes all clients registered to the account

array
GetSessions()

Returns an array of sessions registered to the account

array
GetRecoveryKeys()

Returns an array of recovery keys for the account

bool
HasRecoveryKeys()

True if recovery keys exist for the account

array
GetTwoFactors()

Returns an array of twofactors for the account

bool
HasTwoFactor()

True if a two factor exists for the account

bool
GetForceUseTwoFactor()

True if two factor should be required to create a session even for a pre-existing client

bool
GetAllowCrypto()

True if account-based server-side crypto is allowed

int
GetAllowAccountSearch()

Returns 0 if account search is disabled, or N if up to N matches are allowed

int
GetAllowGroupSearch()

Returns 0 if group search is disabled, or N if up to N matches are allowed

bool
GetAllowUserDelete()

Returns true if the user is allowed to delete their account

bool
isAdmin()

True if this account has administrator privileges

bool
isEnabled()

True if this account is enabled

setAdmin(bool|null $val)

Sets this account's admin-status to the given value

setDisabled(int|null $val = self::DISABLE_PERMANENT)

Sets the account's disabled status to the given enum value

float|null
getActiveDate()

Gets the timestamp when this user was last active

setActiveDate()

Sets the last-active timestamp to now

float|null
getLoggedonDate()

Gets the timestamp when this user last created a session

setLoggedonDate()

Sets the timestamp of last-login to now

float|null
getPasswordDate()

No description

setPasswordDate()

No description

resetPasswordDate()

Sets the account's last password change date to 0, potentially forcing a password reset

int|null
GetClientTimeout()

Returns the maximum allowed time since a client was last active for it to be valid

int|null
GetSessionTimeout()

Returns the maximum allowed time since a session was last active for it to be valid

int|null
GetMaxPasswordAge()

No description

static array
SearchByFullName(ObjectDatabase $database, string $fullname)

Returns an array of accounts with any part of their full name matching the name given

static Account|null
TryLoadByUsername(ObjectDatabase $database, string $username)

Attempts to load an account with the given username

static Account|null
TryLoadByContactInfo(ObjectDatabase $database, ContactInfo $info)

Attempts to load an account with the given contact info

static array
LoadAllMatchingInfo(ObjectDatabase $database, string $info, int $limit)

Returns all accounts whose username, fullname or contacts match the given info

static array
LoadByAuthSource(ObjectDatabase $database, Manager $authman)

Returns an array of all accounts based on the given auth source

static void
DeleteByAuthSource(ObjectDatabase $database, Manager $authman)

Deletes all accounts using the given auth source

array
GetContactEmails()

Returns EmailReceipient objects for all email contacts

EmailRecipient|null
GetEmailFrom()

Returns the EmailRecipient to use for sending email FROM this account

NotifyValidContact()

Sets this account to enabled if it was disabled pending a valid contact

static Account
Create(ObjectDatabase $database, ISource $source, string $username, string $password = null)

Creates a new user account

static 
RegisterDeleteHandler(callable $func)

Registers a function to be run when an account is deleted

array
GetClientObject(int $level = 0)

Gets this account as a printable object

bool
HasValidTwoFactor()

Returns true if the account has a validated two factor and recovery keys

bool
CheckTwoFactor(string $code, bool $force = false)

Checks a two factor code

bool
CheckRecoveryKey(string $key)

Returns true if the given recovery key matches one (and they exist)

bool
VerifyPassword(string $password)

Returns true if the given password is correct for this account

bool
CheckPasswordAge()

Returns true if the account's password is not out of date, or is using external auth

bool
hasCrypto()

Returns true if server-side crypto is unavailable on the account

bool
CryptoAvailable()

Returns true if crypto has been unlocked in this request and is available for operations

ChangePassword(string $new_password)

Re-keys the account's crypto if it exists, and re-hashes its password (if using local auth)

string
GetPasswordHash()

Gets the account's password hash

SetPasswordHash(string $hash)

Sets the account's password hash to the given value

string
EncryptSecret(string $data, string $nonce)

Encrypts a value using the account's crypto

string
DecryptSecret(string $data, string $nonce)

Decrypts a value using the account's crypto

string
GetEncryptedMasterKey(string $nonce, string $key)

Gets a copy of the account's master key, encrypted

UnlockCryptoFromPassword(string $password)

Attempts to unlock crypto using the given password

UnlockCryptoFromKeySource(KeySource $source)

Attempts to unlock crypto using the given unlocked key source

UnlockCryptoFromRecoveryKey(string $key)

Attempts to unlock crypto using a full recovery key

static 
RegisterCryptoHandler(callable $func)

Registers a function to be run when crypto is enabled/disabled on the account

InitializeCrypto(string $password, bool $rekey = false)

Initializes secret-key crypto on the account

DestroyCrypto()

Disables crypto on the account, stripping all keys

__destruct()

No description

Details

at line 45
static array GetFieldTemplate()

Gets a template array of the object's properties (columns).

This template will be copied into the object when it is constructed. If a field maps to null, a basic Scalar fieldtype will be used.

Return Value

array

array of FieldTypes indexed by field names

in BaseObject at line 52
static string GetDBClass()

Returns the name of the class that should be used in the database for the table name (cast down at save)

Defaults to the actual class used. Can be overriden e.g. if multiple classes need to use the same table.

Return Value

string

in BaseObject at line 60
static string GetObjClass(array $row)

No description

Parameters

array $row

Return Value

string

in BaseObject at line 68
static int CountByQuery(ObjectDatabase $database, QueryBuilder $query)

Counts objects in the DB matching the given query

Parameters

ObjectDatabase $database

Reference to the database

QueryBuilder $query

The query to use for matching objects

Return Value

int

count of matched objects

in BaseObject at line 79
static array LoadByQuery(ObjectDatabase $database, QueryBuilder $query)

Loads an array of objects from the DB matching the given query

Parameters

ObjectDatabase $database

Reference to the database

QueryBuilder $query

The query to use for matching objects

Return Value

array

array of objects indexed by their IDs

in BaseObject at line 92
static int DeleteByQuery(ObjectDatabase $database, QueryBuilder $query)

Deletes objects from the DB matching the given query

The objects are loaded when they are deleted and their Delete()s are run

Parameters

ObjectDatabase $database

Reference to the database

QueryBuilder $query

The query to use for matching objects

Return Value

int

number of objects deleted

in BaseObject at line 103
static BaseObject|null TryLoadUniqueByQuery(ObjectDatabase $database, QueryBuilder $query)

Loads a unique object matching the given query

Parameters

ObjectDatabase $database

Reference to the database

QueryBuilder $query

the query to uniquely identify the object

Return Value

BaseObject|null

in BaseObject at line 116
static BaseObject NotNull(BaseObject|null $obj)

Asserts that the given object is not null

Parameters

BaseObject|null $obj

the object to check for null

Return Value

BaseObject

object if not null

Exceptions

ObjectNotFoundException

if the object is null

in BaseObject at line 127
static BaseObject|null TryLoadByID(ObjectDatabase $database, string $id)

Loads a unique object by its ID

Parameters

ObjectDatabase $database

Reference to the database

string $id

the ID of the object

Return Value

BaseObject|null

object or null if not found

in BaseObject at line 137
static void DeleteByID(ObjectDatabase $database, string $id)

Deletes a unique object by its ID

Parameters

ObjectDatabase $database

Reference to the database

string $id

the ID of the object

Return Value

void

in BaseObject at line 150
static array LoadAll(ObjectDatabase $database, int|null $limit = null, int|null $offset = null)

Loads all objects of this type from the database

Parameters

ObjectDatabase $database

Reference to the database

int|null $limit

the maximum number of objects to load

int|null $offset

the number of objects to skip loading

Return Value

array

array of objects indexed by their IDs

in BaseObject at line 160
static int DeleteAll(ObjectDatabase $database)

Deletes all objects of this type from the database

Parameters

ObjectDatabase $database

Reference to the database

Return Value

int

number of deleted objects

in BaseObject at line 176
static array LoadByObjectID(ObjectDatabase $database, string $field, string $id, string|null $class = null)

Loads objects from the database with the given object ID as the value of the given field

Can be used as an alternative to LoadByObject() to avoid actually loading the object

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

string $id

The ID of the object referenced

string|null $class

optionally, the class to match if this column is polymorphic

Return Value

array

array of objects indexed by their IDs

in BaseObject at line 193
static int DeleteByObjectID(ObjectDatabase $database, string $field, string $id, string|null $class = null)

Deletes objects from the database with the given object ID as the value of the given field

Can be used as an alternative to DeleteByObject() to avoid actually loading the object

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

string $id

The ID of the object referenced

string|null $class

optionally, the class to match if this column is polymorphic

Return Value

int

number of rows deleted

in BaseObject at line 206
static protected BaseObject|null TryLoadUniqueByKey(ObjectDatabase $database, string $field, string $key)

Loads a unique object matching the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

the name of the field to check

string $key

the value of the field that uniquely identifies the object

Return Value

BaseObject|null

in BaseObject at line 218
static protected bool TryDeleteByUniqueKey(ObjectDatabase $database, string $field, string $key)

Deletes a unique object matching the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

the name of the field to check

string $key

the value of the field that uniquely identifies the object

Return Value

bool

true if an object was deleted

in BaseObject at line 233
static array LoadByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Loads objects from the database with the given object referenced by the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

BaseObject $object

the object referenced by the field

bool $isPoly

whether or not this field is polymorphic

Return Value

array

array of objects indexed by their IDs

in BaseObject at line 247
static int DeleteByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Deletes objects from the database with the given object referenced by the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

BaseObject $object

the object referenced by the field

bool $isPoly

whether or not this field is polymorphic

Return Value

int

number of deleted objects

in BaseObject at line 261
static BaseObject|null TryLoadUniqueByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Loads a unique object from the database with the given object referenced by the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

BaseObject $object

the object referenced by the field

bool $isPoly

whether or not this field is polymorphic

Return Value

BaseObject|null

in BaseObject at line 275
static bool TryDeleteByUniqueObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Deletes a unique object from the database with the given object referenced by the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

BaseObject $object

the object referenced by the field

bool $isPoly

whether or not this field is polymorphic

Return Value

bool

true if an object was deleted

in BaseObject at line 284
string ID()

Returns the unique ID of the object

Return Value

string

in BaseObject at line 287
string __toString()

Returns the string "id:class" where id is the object ID and class is its short class name

Return Value

string

in BaseObject at line 290
static string|null toString(BaseObject|null $obj)

Returns the given object's as a string if not null, else null

Parameters

BaseObject|null $obj

Return Value

string|null

in GroupInherit at line 817
protected GetScalar(string $field, bool $allowTemp = true)

No description

Parameters

string $field
bool $allowTemp

in GroupInherit at line 825
protected TryGetScalar(string $field, bool $allowTemp = true)

No description

Parameters

string $field
bool $allowTemp

in BaseObject at line 336
protected int GetScalarDelta(string $field)

Returns the delta of the given scalar (non-zero if modified)

Parameters

string $field

the field name of the scalar

Return Value

int

of times modified for scalars, delta for counters

Exceptions

KeyNotFoundException

if the field name is invalid

in GroupInherit at line 832
protected BaseObject GetObject(string $field)

No description

Parameters

string $field

Return Value

BaseObject

in GroupInherit at line 840
protected BaseObject|null TryGetObject(string $field)

No description

Parameters

string $field

Return Value

BaseObject|null

in BaseObject at line 379
protected bool HasObject(string $field)

Checks if the object reference is not-null without actually loading it (faster)

Parameters

string $field

the field name holding the reference

Return Value

bool

true if the object reference is not null

Exceptions

KeyNotFoundException

if the field name is invalid

in BaseObject at line 394
protected string GetObjectID(string $field)

Gets the ID of a referenced object without actually loading it (faster)

Parameters

string $field

the field name holding the reference

Return Value

string

the ID of the referenced object

Exceptions

KeyNotFoundException

if the field name is invalid

NullValueException

if the field value is null

in BaseObject at line 408
protected string|null TryGetObjectID(string $field)

Same as GetObjectID() but returns null instead of throwing exceptions

Parameters

string $field

Return Value

string|null

See also

BaseObject::GetObjectID

in BaseObject at line 422
protected string GetObjectType(string $field)

Gets the class name of a referenced object without actually loading it (faster)

Parameters

string $field

the field name holding the reference

Return Value

string

the class name of the referenced object

Exceptions

KeyNotFoundException

if the field name is invalid

in BaseObject at line 438
protected string|null TryGetObjectType(string $field)

Gets the class name of a referenced object without actually loading it (faster)

Parameters

string $field

the field name holding the reference

Return Value

string|null

the class name of the referenced object

Exceptions

KeyNotFoundException

if the field name is invalid

in BaseObject at line 451
protected BaseObject DeleteObject(string $field)

Deletes the object referenced in the field

Parameters

string $field

the field name holding the reference

Return Value

BaseObject

in BaseObject at line 467
protected array GetObjectRefs(string $field, int|null $limit = null, int|null $offset = null)

Gets an array of objects that reference this object

Parameters

string $field

the field name of the collection

int|null $limit

the maximum number of objects to load

int|null $offset

the number of objects to skip loading

Return Value

array

array of objects indexed by their IDs

Exceptions

KeyNotFoundException

if the field name is invalid

in BaseObject at line 481
protected int CountObjectRefs(string $field)

Gets the counter of objects referencing this object

Parameters

string $field

the field name of the collection

Return Value

int

the number of objects

Exceptions

KeyNotFoundException

if the field name is invalid

in BaseObject at line 497
protected StandardObject GetJoinObject(string $field, BaseObject $obj)

Loads the object that joins together two classes using a FieldTypes\ObjectJoin

Parameters

string $field

the field name using the join reference

BaseObject $obj

the object that is joined together with this one

Return Value

StandardObject

the join object that connects us to $obj

Exceptions

KeyNotFoundException

if the field name is invalid

NullValueException

if the given object is not joined to us

in BaseObject at line 514
protected StandardObject|null TryGetJoinObject(string $field, BaseObject $obj)

Same as GetJoinObject() but returns null instead of throwing exceptions

Parameters

string $field
BaseObject $obj

Return Value

StandardObject|null

See also

BaseObject::GetJoinObject

in BaseObject at line 530
protected BaseObject DeleteObjects(string $field)

Deletes all objects that reference this object

Parameters

string $field

the field name of the collection

Return Value

BaseObject

in BaseObject at line 546
protected BaseObject SetScalar(string $field, mixed $value, bool $temp = false)

Sets a scalar field to the given value

Parameters

string $field

the name of the field

mixed $value

the value of the scalar to set

bool $temp

if true, the value is temporary and will not be saved

Return Value

BaseObject

Exceptions

KeyNotFoundException

if the property name is invalid

in StandardObject at line 173
protected BaseObject DeltaCounter(string $name, int $delta = 1, bool $ignoreLimit = false)

Increment a counter by the given value

Parameters

string $name

the name of the counter field to increment

int $delta

the value to increment by

bool $ignoreLimit

if true, ignore the counter's limit

Return Value

BaseObject

Exceptions

CounterOverLimitException

if the counter's limit exists and is exceeded

See also

\Andromeda\Core\Database\BaseObject::DeltaScalar()

in BaseObject at line 598
protected bool BoolSetObject(string $field, BaseObject|null $object, bool $notification = false)

Sets a field to reference the given object

Will also call SetObject or AddObjectRef on the given object as appropriate for two-way references

Parameters

string $field

the name of the reference field

BaseObject|null $object

the object for the field to reference

bool $notification

true if this is a notification from another object that cross-references this one (internal only!)

Return Value

bool

true if this object was modified

Exceptions

KeyNotFoundException

if the property name is invalid

in BaseObject at line 649
protected BaseObject SetObject(string $field, BaseObject|null $object, bool $notification = false)

Same as BoolSetObject() but returns $this

Parameters

string $field
BaseObject|null $object
bool $notification

Return Value

BaseObject

See also

BaseObject::BoolSetObject

at line 155
protected bool AddObjectRef(string $field, BaseObject $object, bool $notification = false)

Adds an object reference, checking for a limit on the number of references

Parameters

string $field

the name of the field of the collection

BaseObject $object

the object to add to the collection

bool $notification

true if this is a notification from another object that cross-references this one (internal only!)

Return Value

bool

true if this object was modified

Exceptions

CounterOverLimitException

if the limit exists and is exceeded

at line 164
protected bool RemoveObjectRef(string $field, BaseObject $object, bool $notification = false)

Removes the given object from a collection of referenced objects

Parameters

string $field

the name of the field of the collection

BaseObject $object

the object to add to the collection

bool $notification

true if this is a notification from another object that cross-references this one (internal only!)

Return Value

bool

true if this object was modified

Exceptions

KeyNotFoundException

if the property name is invalid

in BaseObject at line 727
__construct(ObjectDatabase $database, array $data)

Constructs the object by initializing its field template with values from the database

Parameters

ObjectDatabase $database

Reference to the database

array $data

array of columns from the DB in the form of name=>value

in BaseObject at line 750
private AddField(string $key, Scalar $field)

Adds the given field object to the correct internal array

Parameters

string $key
Scalar $field

in BaseObject at line 763
protected void SubConstruct()

Function to allow subclasses to do something after being constructed without overriding the constructor

Return Value

void

in BaseObject at line 771
BaseObject Save(bool $onlyMandatory = false)

Collects fields that have changed and saves them to the database

Parameters

bool $onlyMandatory

true if only required fields should be saved

Return Value

BaseObject

Exceptions

RowInsertFailedException

if the insert fails (duplicate?)

in BaseObject at line 814
bool isDeleted()

whether or not this object has been, or should be considered, deleted

This function can be overriden with a custom validity-check, and is used as a filter when loading objects

Return Value

bool

in BaseObject at line 820
void NotifyDBDeleted()

Deletes this object without sending to the DB

Return Value

void

at line 444
void Delete()

Deletes this account and all associated objects

Return Value

void

See also

\Andromeda\Apps\Accounts\BaseObject::Delete()

in BaseObject at line 849
protected void DeleteLater()

Schedules the object to be deleted when Save() is called

Return Value

void

in BaseObject at line 855
bool isCreated()

True if this object has been created and not yet saved to DB (should not be overriden)

Return Value

bool

in StandardObject at line 51
static protected BaseObject BaseCreate(ObjectDatabase $database)

Create the object by setting its created date

Parameters

ObjectDatabase $database

Return Value

BaseObject

See also

BaseObject::BaseCreate

in StandardObject at line 23
protected float GetDate(string $name)

Returns the timestamp value stored in the given date field

Parameters

string $name

Return Value

float

See also

BaseObject::GetScalar

in StandardObject at line 29
protected float|null TryGetDate(string $name)

Returns the timestamp value stored in the given date field

Parameters

string $name

Return Value

float|null

See also

BaseObject::TryGetScalar

in StandardObject at line 38
protected StandardObject SetDate(string $name, float|null $value = null)

Sets the value of the given date field to the given value

Parameters

string $name

the name of the date field to set

float|null $value

the value of the timestamp, or null to use the current time

Return Value

StandardObject

See also

BaseObject::SetScalar

in StandardObject at line 44
float GetDateCreated()

Returns the timestamp when this object was created

Return Value

float

in StandardObject at line 58
protected int GetFeatureInt(string $name, bool $allowTemp = true)

Gets the value of the given feature field as an int (used for config)

Parameters

string $name
bool $allowTemp

Return Value

int

See also

BaseObject::GetScalar

in StandardObject at line 65
protected int|null TryGetFeatureInt(string $name, bool $allowTemp = true)

Gets the value of the given feature field as an int (used for config)

Parameters

string $name
bool $allowTemp

Return Value

int|null

See also

BaseObject::GetScalar

in StandardObject at line 75
protected bool GetFeatureBool(string $name, bool $allowTemp = true)

Gets the value of the given feature field as a bool (used for config)

Parameters

string $name
bool $allowTemp

Return Value

bool

See also

BaseObject::GetScalar

in StandardObject at line 82
protected bool|null TryGetFeatureBool(string $name, bool $allowTemp = true)

Gets the value of the given feature field as a bool (used for config)

Parameters

string $name
bool $allowTemp

Return Value

bool|null

See also

BaseObject::GetScalar

in StandardObject at line 93
protected StandardObject SetFeatureInt(string $name, int|null $value, bool $temp = false)

Sets the value of the given feature field to the given (?int) value

Parameters

string $name
int|null $value
bool $temp

Return Value

StandardObject

See also

BaseObject::SetScalar

in StandardObject at line 101
protected StandardObject SetFeatureBool(string $name, bool|null $value, bool $temp = false)

Sets the value of the given feature field to the given (?bool) value

Parameters

string $name
bool|null $value
bool $temp

Return Value

StandardObject

See also

BaseObject::SetScalar

in StandardObject at line 105
protected bool isFeatureModified(string $name)

Returns true if the given feature has been modified

Parameters

string $name

Return Value

bool

in StandardObject at line 114
protected int GetCounter(string $name)

Gets the value of the given counter field

Parameters

string $name

Return Value

int

See also

BaseObject::GetScalar

in StandardObject at line 121
protected int GetCounterLimit(string $name)

Gets the value of the given counter limit field

Parameters

string $name

Return Value

int

See also

BaseObject::GetScalar

in StandardObject at line 128
protected int|null TryGetCounterLimit(string $name)

Gets the value of the given counter limit field

Parameters

string $name

Return Value

int|null

See also

BaseObject::TryGetScalar

in StandardObject at line 140
protected StandardObject SetCounterLimit(string $name, int|null $value, bool $temp = false)

Sets the value of the given counter limit field

Parameters

string $name
int|null $value
bool $temp

Return Value

StandardObject

See also

BaseObject::SetScalar

in StandardObject at line 151
protected bool CheckCounter(string $name, int $delta = 0, bool $except = true)

Checks whether the given counter plus a delta would exceed the limit

Parameters

string $name

the name of the counter and counter limit field to check

int $delta

the value to try incrementing the counter by

bool $except

if true, throw an exception instead of returning false

Return Value

bool

if true, the limit exists and is not exceeded

Exceptions

CounterOverLimitException

if $except and retval is false

in StandardObject at line 202
protected array GetAllScalars(string|null $prefix)

Gets an array of the values of all fields matching a prefix

Parameters

string|null $prefix

the prefix to match fields against, or null to get all

Return Value

array

mapping field names (stripped of their prefix) to their values

See also

BaseObject::TryGetScalar

at line 99
string GetDisplayName()

Returns the account's full name if set, else its username

Return Value

string

at line 364
array GetContacts(bool $valid = true)

Returns all contacts for this account

Parameters

bool $valid

if true return only validated contacts

Return Value

array

at line 402
void SendMessage(string $subject, string|null $html, string $plain, Account|null $from = null)

Sends a message to all of this account's valid contacts

Parameters

string $subject
string|null $html
string $plain
Account|null $from

Return Value

void

See also

Contact::SendMessageMany

in AuthEntity at line 97
static string GetPropUsage()

defines command usage for SetProperties()

Return Value

string

in AuthEntity at line 106
AuthEntity SetProperties(Input $input)

Sets the value of an inherited property for the object

Parameters

Input $input

Return Value

AuthEntity

in GroupInherit at line 848
protected BaseObject|null TryGetInheritsScalarFrom(string $field)

Returns the object that the value of the given field is inherited from

Parameters

string $field

Return Value

BaseObject|null

in GroupInherit at line 854
protected BaseObject|null TryGetInheritsObjectFrom(string $field)

Returns the object that the value of the given field is inherited from

Parameters

string $field

Return Value

BaseObject|null

in GroupInherit at line 868
protected InheritedProperty TryGetInheritable(string $field, bool $useobj = false)

Returns an inherited property value and source pair

Values can be inherited from this account, from any group it is a member of, or if using a default value, null

Parameters

string $field

the inherited property to find

bool $useobj

true if this is an object reference, not a scalar

Return Value

InheritedProperty

value/source pair

at line 79
static protected array GetInheritedFields()

Gets the fields that can be inherited from a group, with their default values

Return Value

array

at line 96
string GetUsername()

Returns the account's username

Return Value

string

at line 102
Account SetFullName(string $data)

Sets the account's full name

Parameters

string $data

Return Value

Account

at line 108
array GetDefaultGroups()

Loads the groups that the account implicitly belongs to

Return Value

array

groups indexed by ID

at line 129
array GetGroups()

Returns a list of all groups that the account belongs to

Return Value

array

groups indexed by ID

at line 135
array GetMyGroups()

Returns a list of all groups that the account explicitly belongs to

Return Value

array

groups indexed by ID

at line 138
Account AddGroup(Group $group)

Adds the account to the given group

Parameters

Group $group

Return Value

Account

at line 141
Account RemoveGroup(Group $group)

Removes the account from the given group

Parameters

Group $group

Return Value

Account

at line 144
bool HasGroup(Group $group)

Returns true if the account is a member of the given group

Parameters

Group $group

Return Value

bool

at line 149
static RegisterGroupChangeHandler(callable $func)

Registers a function to be run when the account is added to or removed from a group

Parameters

callable $func

at line 152
static RunGroupChangeHandlers(ObjectDatabase $database, Account $account, Group $group, bool $added)

Runs all functions registered to handle the account being added to or removed from a group

Parameters

ObjectDatabase $database
Account $account
Group $group
bool $added

at line 174
GroupJoin|null GetGroupJoin(Group $group)

Returns the object joining this account to the given group

Parameters

Group $group

Return Value

GroupJoin|null

at line 180
ISource GetAuthSource()

Returns the auth source the account authenticates against

Return Value

ISource

at line 191
array GetClients()

Returns an array of clients registered to the account

Return Value

array

clients indexed by ID

at line 194
Account DeleteClients()

Deletes all clients registered to the account

Return Value

Account

at line 200
array GetSessions()

Returns an array of sessions registered to the account

Return Value

array

sessions indexed by ID

at line 206
private array GetRecoveryKeys()

Returns an array of recovery keys for the account

Return Value

array

keys indexed by ID

at line 209
bool HasRecoveryKeys()

True if recovery keys exist for the account

Return Value

bool

at line 215
private array GetTwoFactors()

Returns an array of twofactors for the account

Return Value

array

twofactors indexed by ID

at line 218
bool HasTwoFactor()

True if a two factor exists for the account

Return Value

bool

at line 221
bool GetForceUseTwoFactor()

True if two factor should be required to create a session even for a pre-existing client

Return Value

bool

at line 224
bool GetAllowCrypto()

True if account-based server-side crypto is allowed

Return Value

bool

at line 227
int GetAllowAccountSearch()

Returns 0 if account search is disabled, or N if up to N matches are allowed

Return Value

int

at line 230
int GetAllowGroupSearch()

Returns 0 if group search is disabled, or N if up to N matches are allowed

Return Value

int

at line 233
bool GetAllowUserDelete()

Returns true if the user is allowed to delete their account

Return Value

bool

at line 236
bool isAdmin()

True if this account has administrator privileges

Return Value

bool

at line 239
bool isEnabled()

True if this account is enabled

Return Value

bool

at line 242
Account setAdmin(bool|null $val)

Sets this account's admin-status to the given value

Parameters

bool|null $val

Return Value

Account

at line 245
Account setDisabled(int|null $val = self::DISABLE_PERMANENT)

Sets the account's disabled status to the given enum value

Parameters

int|null $val

Return Value

Account

at line 248
float|null getActiveDate()

Gets the timestamp when this user was last active

Return Value

float|null

at line 251
Account setActiveDate()

Sets the last-active timestamp to now

Return Value

Account

at line 259
float|null getLoggedonDate()

Gets the timestamp when this user last created a session

Return Value

float|null

at line 262
Account setLoggedonDate()

Sets the timestamp of last-login to now

Return Value

Account

at line 264
private float|null getPasswordDate()

No description

Return Value

float|null

at line 265
private Account setPasswordDate()

No description

Return Value

Account

at line 268
Account resetPasswordDate()

Sets the account's last password change date to 0, potentially forcing a password reset

Return Value

Account

at line 271
int|null GetClientTimeout()

Returns the maximum allowed time since a client was last active for it to be valid

Return Value

int|null

at line 274
int|null GetSessionTimeout()

Returns the maximum allowed time since a session was last active for it to be valid

Return Value

int|null

at line 276
private int|null GetMaxPasswordAge()

No description

Return Value

int|null

at line 284
static array SearchByFullName(ObjectDatabase $database, string $fullname)

Returns an array of accounts with any part of their full name matching the name given

Parameters

ObjectDatabase $database

database reference

string $fullname

the name fragment to search for

Return Value

array

Accounts indexed by ID

at line 295
static Account|null TryLoadByUsername(ObjectDatabase $database, string $username)

Attempts to load an account with the given username

Parameters

ObjectDatabase $database

database reference

string $username

username to load for

Return Value

Account|null

loaded account or null if not found

at line 306
static Account|null TryLoadByContactInfo(ObjectDatabase $database, ContactInfo $info)

Attempts to load an account with the given contact info

Parameters

ObjectDatabase $database

database reference

ContactInfo $info

the contact info type/value

Return Value

Account|null

loaded account or null if not found

at line 320
static array LoadAllMatchingInfo(ObjectDatabase $database, string $info, int $limit)

Returns all accounts whose username, fullname or contacts match the given info

Parameters

ObjectDatabase $database

database reference

string $info

username/other info to match by (wildcard)

int $limit

max # to load - returns nothing if exceeded (in a single category)

Return Value

array

Account

See also

Account::GetClientObject

at line 344
static array LoadByAuthSource(ObjectDatabase $database, Manager $authman)

Returns an array of all accounts based on the given auth source

Parameters

ObjectDatabase $database

database reference

Manager $authman

authentication source

Return Value

array

accounts indexed by ID

at line 354
static void DeleteByAuthSource(ObjectDatabase $database, Manager $authman)

Deletes all accounts using the given auth source

Parameters

ObjectDatabase $database

database reference

Manager $authman

authentication source

Return Value

void

at line 378
array GetContactEmails()

Returns EmailReceipient objects for all email contacts

Return Value

array

at line 391
EmailRecipient|null GetEmailFrom()

Returns the EmailRecipient to use for sending email FROM this account

Return Value

EmailRecipient|null

email recipient object or null if not set

at line 408
Account NotifyValidContact()

Sets this account to enabled if it was disabled pending a valid contact

Return Value

Account

at line 421
static Account Create(ObjectDatabase $database, ISource $source, string $username, string $password = null)

Creates a new user account

Parameters

ObjectDatabase $database

database reference

ISource $source

the auth source for the account

string $username

the account's username

string $password

the account's password, if not external auth

Return Value

Account

created account

at line 438
static RegisterDeleteHandler(callable $func)

Registers a function to be run when an account is deleted

Parameters

callable $func

at line 471
array GetClientObject(int $level = 0)

Gets this account as a printable object

Parameters

int $level

Return Value

array

{id:id,username:string,dispname:string} \ if OBJECT_FULL or OBJECT_ADMIN, add: {dates:{created:float,passwordset:?float,loggedon:?float,active:?float}, counters:{groups:int,sessions:int,contacts:int,clients:int,twofactors:int,recoverykeys:int}, limits:{sessions:?int,contacts:?int,recoverykeys:?int}, features:{admin:bool,disabled:int,forcetf:bool,allowcrypto:bool accountsearch:int, groupsearch:int, userdelete:bool},session_timeout:?int,client_timeout:?int,max_password_age:?int} \ if OBJECT_FULL, add: {contacts:[id:Contact], clients:[id:Client], twofactors:[id:TwoFactor]} \ if OBJECT_ADMIN, add: {twofactor:bool, comment:?string, groups:[id], limits_from:[string:"id:class"], dates:{modified:?float}, features_from:[string:"id:class"], session_timeout_from:"id:class", client_timeout_from:"id:class", max_password_age_from:"id:class"}

See also

Contact::GetClientObject
TwoFactor::GetClientObject
Client::GetClientObject

at line 547
bool HasValidTwoFactor()

Returns true if the account has a validated two factor and recovery keys

Return Value

bool

at line 562
bool CheckTwoFactor(string $code, bool $force = false)

Checks a two factor code

Parameters

string $code

the given twofactor code

bool $force

if true, accept non-valid twofactor sources

Return Value

bool

true if there is a valid twofactor (or force) and the code is valid

at line 572
bool CheckRecoveryKey(string $key)

Returns true if the given recovery key matches one (and they exist)

Parameters

string $key

Return Value

bool

at line 584
bool VerifyPassword(string $password)

Returns true if the given password is correct for this account

Parameters

string $password

Return Value

bool

at line 590
bool CheckPasswordAge()

Returns true if the account's password is not out of date, or is using external auth

Return Value

bool

at line 601
bool hasCrypto()

Returns true if server-side crypto is unavailable on the account

Return Value

bool

at line 606
bool CryptoAvailable()

Returns true if crypto has been unlocked in this request and is available for operations

Return Value

bool

at line 609
Account ChangePassword(string $new_password)

Re-keys the account's crypto if it exists, and re-hashes its password (if using local auth)

Parameters

string $new_password

Return Value

Account

at line 625
string GetPasswordHash()

Gets the account's password hash

Return Value

string

at line 628
Account SetPasswordHash(string $hash)

Sets the account's password hash to the given value

Parameters

string $hash

Return Value

Account

at line 637
string EncryptSecret(string $data, string $nonce)

Encrypts a value using the account's crypto

Parameters

string $data

the plaintext to be encrypted

string $nonce

the nonce to use for crypto

Return Value

string

the ciphertext encrypted with the account's secret key

Exceptions

CryptoUnlockRequiredException

if crypto has not been unlocked

at line 652
string DecryptSecret(string $data, string $nonce)

Decrypts a value using the account's crypto

Parameters

string $data

the ciphertext to be decrypted

string $nonce

the nonce used for encryption

Return Value

string

the plaintext decrypted with the account's key

Exceptions

CryptoUnlockRequiredException

if crypto has not been unlocked

at line 667
string GetEncryptedMasterKey(string $nonce, string $key)

Gets a copy of the account's master key, encrypted

Parameters

string $nonce

the nonce to use for encryption

string $key

the key to use for encryption

Return Value

string

the encrypted copy of the master key

Exceptions

CryptoUnlockRequiredException

if crypto has not been unlocked

at line 678
Account UnlockCryptoFromPassword(string $password)

Attempts to unlock crypto using the given password

Parameters

string $password

Return Value

Account

Exceptions

CryptoNotInitializedException

if crypto does not exist

DecryptionFailedException

if decryption fails

at line 702
Account UnlockCryptoFromKeySource(KeySource $source)

Attempts to unlock crypto using the given unlocked key source

Parameters

KeySource $source

Return Value

Account

Exceptions

CryptoNotInitializedException

if crypto does not exist

DecryptionFailedException

if decryption fails

at line 722
Account UnlockCryptoFromRecoveryKey(string $key)

Attempts to unlock crypto using a full recovery key

Parameters

string $key

Return Value

Account

Exceptions

CryptoNotInitializedException

if crypto does not exist

RecoveryKeyFailedException

if the key is not valid

DecryptionFailedException

if decryption fails

at line 741
static RegisterCryptoHandler(callable $func)

Registers a function to be run when crypto is enabled/disabled on the account

Parameters

callable $func

at line 756
Account InitializeCrypto(string $password, bool $rekey = false)

Initializes secret-key crypto on the account

Accounts have a master-key for secret-key crypto. The master-key is generated randomly and then wrapped using a key derived from the user's password and a nonce/salt. Requests that require use of account crypto therefore must have the user's password or some other key source material transmitted in each request. The crypto is of course done server-side, but the raw keys are only ever available in memory, not in the database.

Parameters

string $password

the password to derive keys from

bool $rekey

true if crypto exists and we want to keep the same master key

Return Value

Account

Exceptions

CryptoUnlockRequiredException

if crypto is not unlocked

CryptoAlreadyInitializedException

if crypto already exists and not re-keying

at line 788
Account DestroyCrypto()

Disables crypto on the account, stripping all keys

Return Value

Account

at line 804
__destruct()

No description