Member

Reference for the Member module: member records, authentication logins and passwords, login and password-reset codes with permalinks, login-state session helpers, and the routing that mounts the member pages.

This page is a pure reference. For how the framework fits together, see the Guide.

Classes

Member

Defines the member web routes: login, logout, register (when enabled), the forgot-password flow, password reset, and generic code entry. Registered by the application into the route tree.

Functions

Route

Member::Route(): void

Define the member pages under the current route position: login, logout, register (only when MEMBER_REGISTER_ENABLED), the forgot-password flow, password reset, and generic code entry.

Returns void

MemberAuthData

An authentication login for a member: the auth type and login identifier, whether it is verified, and when. Immutable, with conversion to and from JSON.

Properties

PropertyTypeDescription
$auth->idintThe auth record id (readonly).
$auth->memberIdintThe id of the member the login belongs to (readonly).
$auth->authTypestringThe auth type, for example Email or Mobile (readonly).
$auth->authLoginstringThe login identifier, for example the email address or phone number (readonly).
$auth->verifiedboolWhether the login has been verified (readonly).
$auth->optionalVerifiedTimestamp?CalendarDateTimeDataWhen the login was verified, or null (readonly, field named verifiedTimestamp).

__construct

new MemberAuthData(int $id = 0, int $memberId = 0, string $authType = '', string $authLogin = '', bool $verified = false, ?CalendarDateTimeData $verifiedTimestamp = null)

Create an authentication login record.

NameTypeDescription
$idintThe auth record id.
$memberIdintThe id of the member the login belongs to.
$authTypestringThe auth type, for example Email or Mobile.
$authLoginstringThe login identifier.
$verifiedboolWhether the login has been verified.
$verifiedTimestamp?CalendarDateTimeDataWhen the login was verified, or null.

Returns MemberAuthData

FromJson

MemberAuthData::FromJson(string $json): MemberAuthData

Build an auth record from its JSON string.

NameTypeDescription
$jsonstringThe JSON produced by ToJson.

Returns MemberAuthData The decoded auth record.

ToJson

$auth->ToJson(): string

Encode the auth record as a JSON string.

Returns string The JSON representation.

MemberAuthDatabase

Read and write member authentication login records: look up by type and login, by member, or by id; create logins; mark them verified; verify credentials; and read the preferred email address for a member.

CountByMemberId

MemberAuthDatabase::CountByMemberId(int $memberId): int

Count the authentication login records for a member.

NameTypeDescription
$memberIdintThe member to count logins for.

Returns int The number of login records.

Create

MemberAuthDatabase::Create(int $memberId, string $authLogin, string $authType): int

Create a new authentication login record for a member.

NameTypeDescription
$memberIdintThe member the login belongs to.
$authLoginstringThe login identifier.
$authTypestringThe auth type, for example Email or Mobile.

Returns int The id of the new login record.

GetByAuthAndMemberID

MemberAuthDatabase::GetByAuthAndMemberID(int $memberId, string $authType): MemberAuthData

Get a member's login of a given type. Throws when the member has no login of that type.

NameTypeDescription
$memberIdintThe member to read a login for.
$authTypestringThe auth type to read.

Returns MemberAuthData The matching login record.

GetById

MemberAuthDatabase::GetById(int $authId): MemberAuthData

Get an authentication login record by its id.

NameTypeDescription
$authIdintThe auth record id.

Returns MemberAuthData The login record.

GetByMemberId

MemberAuthDatabase::GetByMemberId(int $memberId): array

Get all authentication login records for a member.

NameTypeDescription
$memberIdintThe member to read logins for.

Returns array A list of MemberAuthData.

GetByTypeAndLogin

MemberAuthDatabase::GetByTypeAndLogin(string $authType, string $authLogin): MemberAuthData

Get an authentication login by its type and login identifier. Throws when none is found.

NameTypeDescription
$authTypestringThe auth type to match.
$authLoginstringThe login identifier to match.

Returns MemberAuthData The matching login record.

GetByTypeAndLoginOptional

MemberAuthDatabase::GetByTypeAndLoginOptional(string $authType, string $authLogin): ?MemberAuthData

Get an authentication login by its type and login identifier, or null when none is found.

NameTypeDescription
$authTypestringThe auth type to match.
$authLoginstringThe login identifier to match.

Returns ?MemberAuthData The matching login record, or null.

GetPreferredEmail

MemberAuthDatabase::GetPreferredEmail(int $memberId, string $fallbackEmail = 'noreply@frenziapp.co.uk'): string

The preferred email address for a member: a verified email login, then any email login, then the fallback.

NameTypeDescription
$memberIdintThe member to read an email for.
$fallbackEmailstringThe address returned when the member has no email login.

Returns string The preferred email address.

GetVerifiedByMemberIdAndType

MemberAuthDatabase::GetVerifiedByMemberIdAndType(int $memberId, string $authType): ?MemberAuthData

Get a member's verified login of a given type, or null when none is verified.

NameTypeDescription
$memberIdintThe member to read a login for.
$authTypestringThe auth type to read.

Returns ?MemberAuthData The verified login record, or null.

Verify

MemberAuthDatabase::Verify(int $authId): void

Mark an authentication login record as verified, recording the current time.

NameTypeDescription
$authIdintThe auth record to verify.

Returns void

VerifyLogin

MemberAuthDatabase::VerifyLogin(string $authLogin, string $authType, string $password = ''): ?int

Check login credentials. For the Email type a password is verified; returns the member id when correct, or null.

NameTypeDescription
$authLoginstringThe login identifier.
$authTypestringThe auth type, for example Email or Mobile.
$passwordstringThe plain-text password, checked for the Email type.

Returns ?int The member id when the credentials are correct, or null.

MemberCodeData

Immutable data for a single verification code: its permalink, type, code value, the auth record and member it belongs to, send and expiry timestamps, and status. Fields and constructor only.

Properties

PropertyTypeDescription
$code->permalinkPermalinkDataThe code's permalink (readonly).
$code->authIdintThe auth record the code was issued for (readonly).
$code->codeTypeNamestringThe registered code type name (readonly).
$code->codestringThe code value entered by the member (readonly).
$code->lastSendTimestampintUnix time the code was last sent (readonly).
$code->expiryTimestampintUnix time the code expires (readonly).
$code->memberIdintThe member the code belongs to (readonly).
$code->statusintThe code status; see the MemberCodeDatabase status constants (readonly).
Functions

__construct

new MemberCodeData(PermalinkData $permalink, int $authId = 0, string $codeTypeName = '', string $code = '', int $lastSendTimestamp = 0, int $expiryTimestamp = 0, int $memberId = 0, int $status = 0)

Create a verification code record.

NameTypeDescription
$permalinkPermalinkDataThe code's permalink.
$authIdintThe auth record the code was issued for.
$codeTypeNamestringThe registered code type name.
$codestringThe code value.
$lastSendTimestampintUnix time the code was last sent.
$expiryTimestampintUnix time the code expires.
$memberIdintThe member the code belongs to.
$statusintThe code status.

Returns MemberCodeData

MemberCodeDatabase

Create verification codes and their permalinks, look them up by info, id or permalink, enforce the resend delay, validate an entered code, and generate a random code value.

Constants

ConstantValueDescription
MemberCodeDatabase::STATUS_UNUSED1The code has not yet been used.
MemberCodeDatabase::STATUS_USED2The code has been used.
MemberCodeDatabase::DEFAULT_EXPIRY60*60The default code lifetime in seconds (one hour).
MemberCodeDatabase::DEFAULT_EMAIL_DELAY_SECONDS5The default minimum delay between email code sends.

GetById

MemberCodeDatabase::GetById(int $codeId): MemberCodeData

Fetch a code by id, without checking its status or expiry.

NameTypeDescription
$codeIdintThe code id.

Returns MemberCodeData The code record.

GetByInfo

MemberCodeDatabase::GetByInfo(string $codeTypeName, int $authId, int $memberId): MemberCodeData

Fetch the newest unused, unexpired code for a code type, auth record and member. Throws when none is active.

NameTypeDescription
$codeTypeNamestringThe registered code type name.
$authIdintThe auth record the code was issued for.
$memberIdintThe member the code belongs to.

Returns MemberCodeData The active code record.

MemberCodeDatabase::GetByPermalink(PermalinkData $permalink): MemberCodeData

Fetch a code by its permalink, without checking its status or expiry.

NameTypeDescription
$permalinkPermalinkDataThe code's permalink.

Returns MemberCodeData The code record.

GetOrCreate

MemberCodeDatabase::GetOrCreate(string $codeTypeName, int $authId, int $memberId, int $expirySeconds = MemberCodeDatabase::DEFAULT_EXPIRY): MemberCodeData

Return the active code for a code type, auth record and member, or create a new one with a permalink when none exists.

NameTypeDescription
$codeTypeNamestringThe registered code type name.
$authIdintThe auth record the code is issued for.
$memberIdintThe member the code belongs to.
$expirySecondsintHow long a new code stays valid, in seconds.

Returns MemberCodeData The existing or newly created code record.

RandomCode

MemberCodeDatabase::RandomCode(string $allowedChars = '0123456789', int $length = 6): string

Generate a random code of the given length from the allowed characters.

NameTypeDescription
$allowedCharsstringThe characters the code may contain.
$lengthintThe number of characters in the code.

Returns string The generated code.

UpdateLastSendTimestampIfDelayPassed

MemberCodeDatabase::UpdateLastSendTimestampIfDelayPassed(MemberCodeData $codeData, int $delaySeconds): bool

Record a fresh send timestamp only if the minimum delay has passed since the last send.

NameTypeDescription
$codeDataMemberCodeDataThe code to update.
$delaySecondsintThe minimum delay between sends, in seconds.

Returns bool True when the delay had passed and the timestamp was updated, false when sent too recently.

Validate

MemberCodeDatabase::Validate(MemberCodeData $codeData, string $code): void

Validate an entered code and mark it used. Throws when the code has expired, or when the value is incorrect or already used.

NameTypeDescription
$codeDataMemberCodeDataThe code being validated.
$codestringThe value entered by the member.

Returns void

MemberCodeRoute

Route the code permalink type. Looks up a currently valid code from its permalink and passes it to a callback; expired codes are still passed, and missing or used codes fall through.

Functions
MemberCodeRoute::Permalink(Callable $routeCallback): void

Register the member_code permalink type; on a match the resolved MemberCodeData is passed to the callback.

NameTypeDescription
$routeCallbackCallableCalled with the resolved MemberCodeData.

Returns void

MemberData

Immutable data for a single member: id, when it was added, and whether and when it was soft-deleted. Fields and constructor only.

Properties

PropertyTypeDescription
$member->idintThe member id (readonly).
$member->addedCalendarDateTimeDataWhen the member was added (readonly).
$member->deletedboolWhether the member is soft-deleted (readonly).
$member->optionalDeletedTimestamp?CalendarDateTimeDataWhen the member was deleted, or null (readonly, field named deletedTimestamp).
Functions

__construct

new MemberData(int $id = 0, CalendarDateTimeData $added = new CalendarDateTimeData(), bool $deleted = false, ?CalendarDateTimeData $deletedTimestamp = null)

Create a member record.

NameTypeDescription
$idintThe member id.
$addedCalendarDateTimeDataWhen the member was added.
$deletedboolWhether the member is soft-deleted.
$deletedTimestamp?CalendarDateTimeDataWhen the member was deleted, or null.

Returns MemberData

MemberDatabase

Create, read and soft-delete member records, look members up by email or auth login, count them, and read a member's feature flags.

Count

MemberDatabase::Count(): int

The total number of member records.

Returns int The member count.

Create

MemberDatabase::Create(): int

Create a new member record, stamped with the current time.

Returns int The id of the new member.

Delete

MemberDatabase::Delete(int $memberId): void

Soft-delete a member, recording the deletion time.

NameTypeDescription
$memberIdintThe member to delete.

Returns void

GetAllFeatures

MemberDatabase::GetAllFeatures(int $memberId): array

The current feature flags for a member, one per module and name, taking the latest record in each group.

NameTypeDescription
$memberIdintThe member to read features for.

Returns array A list of objects with moduleName, featureName and active fields.

GetAuthMethodForCodeType

MemberDatabase::GetAuthMethodForCodeType(string $codeTypeName, int $memberId): ?string

Decide which auth method a code type should use for a member, defaulting to Email.

NameTypeDescription
$codeTypeNamestringThe code type name.
$memberIdintThe member the code is for.

Returns ?string The auth method name, or null.

GetByEmail

MemberDatabase::GetByEmail(string $email): ?MemberData

Get the member that owns an email login, or null when no member has that email.

NameTypeDescription
$emailstringThe email address to look up.

Returns ?MemberData The member, or null.

GetById

MemberDatabase::GetById(int $memberId): MemberData

Get a member record by its id. Throws when the member is not found.

NameTypeDescription
$memberIdintThe member id.

Returns MemberData The member record.

GetIDByAuthLoginOptional

MemberDatabase::GetIDByAuthLoginOptional(string $authType, string $authLogin): ?int

Get the member id that owns an auth login of a given type, or null when none matches.

NameTypeDescription
$authTypestringThe auth type, for example Email or Mobile.
$authLoginstringThe login identifier.

Returns ?int The member id, or null.

HasFeature

MemberDatabase::HasFeature(int $memberId, string $moduleName, string $featureName): bool

Whether a member's latest flag for a module feature is active.

NameTypeDescription
$memberIdintThe member to check.
$moduleNamestringThe module that owns the feature.
$featureNamestringThe feature name.

Returns bool True when the feature is active.

Undelete

MemberDatabase::Undelete(int $memberId): void

Reverse a soft delete, clearing the deletion flag and time.

NameTypeDescription
$memberIdintThe member to restore.

Returns void

MemberForgotCode

The password-reset code flow: get or create a reset code for a member, handle a correct code by verifying logins and redirecting to the reset page, and resend a code within the delay rules.

GetCode

MemberForgotCode::GetCode(int $memberId): MemberCodeData

Get or create a password-reset code for a member, preferring an Email login and falling back to Mobile.

NameTypeDescription
$memberIdintThe member to issue a code for.

Returns MemberCodeData The reset code record.

OnCodeEntered

MemberForgotCode::OnCodeEntered(MemberCodeData $code): void

Handle a correct reset code: verify the member's unverified logins and redirect to the password-reset page with the permalink.

NameTypeDescription
$codeMemberCodeDataThe code that was entered correctly.

Returns void

ResendCode

MemberForgotCode::ResendCode(MemberCodeData $codeData): MemberCodeData

Resend a reset code, creating a fresh one when expired, and calling the auth method's send callback. Throws when sent too recently.

NameTypeDescription
$codeDataMemberCodeDataThe code to resend.

Returns MemberCodeData The sent code record.

MemberLoginCode

The login code flow, shared by all auth methods: handle a correct login code by verifying the login and logging the member in, and resend a code within the delay rules.

OnCodeEntered

MemberLoginCode::OnCodeEntered(MemberCodeData $code): void

Handle a correct login code: verify the auth login used, log the member in, and redirect.

NameTypeDescription
$codeMemberCodeDataThe code that was entered correctly.

Returns void

ResendCode

MemberLoginCode::ResendCode(MemberCodeData $codeData): MemberCodeData

Resend a login code, creating a fresh one when expired, and calling the auth method's send callback. Throws when sent too recently.

NameTypeDescription
$codeDataMemberCodeDataThe code to resend.

Returns MemberCodeData The sent code record.

MemberPasswordData

A hashed password record for a member: id, member id, the stored hash, and when it was added. Immutable, with conversion to and from JSON.

Properties

PropertyTypeDescription
$password->idintThe password record id (readonly).
$password->memberIdintThe member the password belongs to (readonly).
$password->passwordHashedstringThe stored password hash (readonly).
$password->addedTimestampCalendarDateTimeDataWhen the password was added (readonly).

__construct

new MemberPasswordData(int $id = 0, int $memberId = 0, string $passwordHashed = '', CalendarDateTimeData $addedTimestamp = new CalendarDateTimeData())

Create a hashed password record.

NameTypeDescription
$idintThe password record id.
$memberIdintThe member the password belongs to.
$passwordHashedstringThe stored password hash.
$addedTimestampCalendarDateTimeDataWhen the password was added.

Returns MemberPasswordData

FromJson

MemberPasswordData::FromJson(string $json): MemberPasswordData

Build a password record from its JSON string.

NameTypeDescription
$jsonstringThe JSON produced by ToJson.

Returns MemberPasswordData The decoded password record.

ToJson

$password->ToJson(): string

Encode the password record as a JSON string.

Returns string The JSON representation.

MemberPasswordDatabase

Store and verify member passwords: verify a login, create and update hashed password records, and read, list and count them.

Count

MemberPasswordDatabase::Count(?int $memberId = null): int

Count password records, optionally filtered to one member.

NameTypeDescription
$memberId?intA member to filter by, or null for all records.

Returns int The number of password records.

Create

MemberPasswordDatabase::Create(int $memberId, string $password): int

Hash a plain-text password with bcrypt and store it as a new record for the member.

NameTypeDescription
$memberIdintThe member the password belongs to.
$passwordstringThe plain-text password.

Returns int The id of the new password record.

GetById

MemberPasswordDatabase::GetById(int $passwordId): MemberPasswordData

Get a password record by its id. Throws when it is not found.

NameTypeDescription
$passwordIdintThe password record id.

Returns MemberPasswordData The password record.

GetByMemberId

MemberPasswordDatabase::GetByMemberId(int $memberId): array

List all password records for a member.

NameTypeDescription
$memberIdintThe member to read passwords for.

Returns array A list of MemberPasswordData.

GetLatestByMemberId

MemberPasswordDatabase::GetLatestByMemberId(int $memberId): ?MemberPasswordData

Get the most recent password record for a member, or null when there is none.

NameTypeDescription
$memberIdintThe member to read a password for.

Returns ?MemberPasswordData The latest password record, or null.

List

MemberPasswordDatabase::List(int $start = 0, int $count = 100, ?int $memberId = null): array

List password records with paging, optionally filtered to one member.

NameTypeDescription
$startintThe offset of the first record.
$countintThe maximum number of records to return.
$memberId?intA member to filter by, or null for all records.

Returns array A list of MemberPasswordData.

Login

MemberPasswordDatabase::Login(int $memberId, string $password): bool

Verify a plain-text password against a member's most recent stored hash.

NameTypeDescription
$memberIdintThe member to check.
$passwordstringThe plain-text password to verify.

Returns bool True when the password matches.

Update

MemberPasswordDatabase::Update(int $passwordId, string $password): void

Replace an existing password record's hash with a new bcrypt hash of the given password.

NameTypeDescription
$passwordIdintThe password record to update.
$passwordstringThe new plain-text password.

Returns void

MemberRoute

Routing combinators that branch a block of route definitions on login state. These are display choosers, not security: they only decide whether to run a block. During the scan pass both branches always run so named routes are discovered.

Functions

LoggedIn

MemberRoute::LoggedIn(callable $routes): void

Define the routes only for a logged-in member, and always during the scan pass.

NameTypeDescription
$routescallableThe block of route definitions.

Returns void

NotLoggedIn

MemberRoute::NotLoggedIn(callable $routes): void

Define the routes only for a logged-out visitor, and always during the scan pass.

NameTypeDescription
$routescallableThe block of route definitions.

Returns void

MemberSecurity

Enforce that a member is logged in. Unlike MemberRoute, this throws when the requirement is not met.

Functions

LoggedIn

MemberSecurity::LoggedIn(): void

Assert that a member is logged in, throwing when no member is.

Returns void

MemberSession

The logged-in member held in the session: read the current member id, test login state, check a feature flag, and log a member in or out (firing the registered login and logout callbacks).

GetLoggedInId

MemberSession::GetLoggedInId(): int

The id of the currently logged-in member. Throws when no member is logged in.

Returns int The logged-in member id.

HasFeature

MemberSession::HasFeature(string $moduleName, string $featureName): bool

Whether the logged-in member has an active, registered feature flag. Returns false when logged out or the feature is unknown.

NameTypeDescription
$moduleNamestringThe module that owns the feature.
$featureNamestringThe feature name.

Returns bool True when the feature is active.

IsLoggedIn

MemberSession::IsLoggedIn(): bool

Whether a member is currently logged in.

Returns bool True when a member is logged in.

Login

MemberSession::Login(int $memberId): void

Log a member in, storing the id in the session and firing the registered login callbacks.

NameTypeDescription
$memberIdintThe member to log in.

Returns void

Logout

MemberSession::Logout(): void

Log the current member out, clearing the session and firing the registered logout callbacks.

Returns void

MemberUrl

Build the URLs of the member pages. The mount base comes from the MEMBER_URL config value; each page path is read from the route name recorded during the scan pass, with any parameter tail composed on.

Code

MemberUrl::Code(PermalinkData $codePermalink): string

The URL of the code-entry page for a code permalink.

NameTypeDescription
$codePermalinkPermalinkDataThe code's permalink.

Returns string The code-entry page URL.

MemberUrl::CodeLink(PermalinkData $codePermalink, string $code): string

The URL that enters a specific code for a code permalink directly.

NameTypeDescription
$codePermalinkPermalinkDataThe code's permalink.
$codestringThe code value to enter.

Returns string The direct code-entry URL.

Forgot

MemberUrl::Forgot(?string $methodName = null): string

The URL of the forgot-password page, optionally for a specific auth method.

NameTypeDescription
$methodName?stringAn auth method to append, or null for the base page.

Returns string The forgot-password page URL.

Login

MemberUrl::Login(): string

The URL of the login page.

Returns string The login page URL.

PasswordReset

MemberUrl::PasswordReset(): string

The URL of the password-reset page.

Returns string The password-reset page URL.

Register

MemberUrl::Register(): string

The URL of the registration page.

Returns string The registration page URL.

Root

MemberUrl::Root(): string

The member mount base, read from the MEMBER_URL config value.

Returns string The member base URL.