Properties

$ident

$ident : string

Type

string

$token

$token : string

Type

string

$username

$username : string

The username should be unique and mandatory.

Type

string

$expiry

$expiry : \Charcoal\User\DatetimeInterface

Type

\Charcoal\User\DatetimeInterface

$created

$created : \DateTimeInterface

Token creation date (set automatically on save)

Type

\DateTimeInterface

$lastModified

$lastModified : \DateTimeInterface

Token last modified date (set automatically on save and update)

Type

\DateTimeInterface

Methods

key()

key() : string

Returns

string

setIdent()

setIdent(string  $ident) : \Charcoal\User\AuthToken

Parameters

string $ident

The token ident.

Returns

\Charcoal\User\AuthToken

Chainable

ident()

ident() : string

Returns

string

setToken()

setToken(string  $token) : \Charcoal\User\AuthToken

Parameters

string $token

The token.

Returns

\Charcoal\User\AuthToken

Chainable

token()

token() : string

Returns

string

setUsername()

setUsername(string  $username) : \Charcoal\User\User

Force a lowercase username

Parameters

string $username

The username (also the login name).

Throws

\InvalidArgumentException

If the username is not a string.

Returns

\Charcoal\User\User —

Chainable

username()

username() : string

Returns

string

setExpiry()

setExpiry(\DateTime|string|null  $expiry) : \Charcoal\User\Content

Parameters

\DateTime|string|null $expiry

The date/time at object's creation.

Throws

\InvalidArgumentException

If the date/time is invalid.

Returns

\Charcoal\User\Content —

Chainable

expiry()

expiry() : \DateTimeInterface|null

Returns

\DateTimeInterface|null

setCreated()

setCreated(\DateTime|string|null  $created) : \Charcoal\User\Content

Parameters

\DateTime|string|null $created

The date/time at object's creation.

Throws

\InvalidArgumentException

If the date/time is invalid.

Returns

\Charcoal\User\Content —

Chainable

created()

created() : \DateTime|null

Returns

\DateTime|null

setLastModified()

setLastModified(\DateTime|string|null  $lastModified) : \Charcoal\User\Content

Parameters

\DateTime|string|null $lastModified

The last modified date/time.

Throws

\InvalidArgumentException

If the date/time is invalid.

Returns

\Charcoal\User\Content —

Chainable

lastModified()

lastModified() : \DateTime

Returns

\DateTime

generate()

generate(string  $username) : \Charcoal\User\AuthToken

Note: the `random_bytes()` function is new to PHP-7. Available in PHP 5 with `compat-random`.

Parameters

string $username

The username to generate the auth token from.

Returns

\Charcoal\User\AuthToken

Chainable

preSave()

preSave() : boolean

StorableTrait > preSave(): Called automatically before saving the object to source.

Returns

boolean

preUpdate()

preUpdate(array  $properties = null) : boolean

StorableTrait > preUpdate(): Called automatically before updating the object to source.

Parameters

array $properties

The properties (ident) set for update.

Returns

boolean

getTokenDataFromCookie()

getTokenDataFromCookie() : array

Returns

array —

`['ident'=>'', 'token'=>'']

getUserId()

getUserId(mixed  $ident, string  $token) : mixed

Parameters

mixed $ident

The auth-token identifier.

string $token

The token key to validate against.

Returns

mixed —

The user id.

getUsernameFromToken()

getUsernameFromToken(mixed  $ident, string  $token) : mixed

Parameters

mixed $ident

The auth-token identifier (username).

string $token

The token to validate against.

Returns

mixed —

The user id. An empty string if no token match.

panic()

panic() : void

Something is seriously wrong: a cookie ident was in the database but with a tampered token.

createMetadata()

createMetadata(array  $data = null) : \Charcoal\User\MetadataInterface

DescribableTrait > create_metadata().

Parameters

array $data

Optional data to intialize the Metadata object with.

Returns

\Charcoal\User\MetadataInterface