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.
Member- defines the member web routes (login, logout, register, forgot, reset, code).MemberAuthData- an authentication login for a member, with JSON conversion.MemberAuthDatabase- read and write member authentication login records.MemberCodeData- immutable data for a single verification code.MemberCodeDatabase- create, look up and validate verification codes.MemberCodeRoute- route a code permalink to a callback.MemberData- immutable data for a single member.MemberDatabase- create, read and soft-delete member records and read feature flags.MemberForgotCode- the password-reset code flow.MemberLoginCode- the login code flow.MemberPasswordData- a hashed password record for a member, with JSON conversion.MemberPasswordDatabase- store and verify member passwords.MemberRoute- branch a block of routes on login state.MemberSecurity- assert that a member is logged in.MemberSession- the logged-in member held in the session.MemberUrl- build the URLs of the member pages.
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.
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
| Property | Type | Description |
|---|---|---|
$auth->id | int | The auth record id (readonly). |
$auth->memberId | int | The id of the member the login belongs to (readonly). |
$auth->authType | string | The auth type, for example Email or Mobile (readonly). |
$auth->authLogin | string | The login identifier, for example the email address or phone number (readonly). |
$auth->verified | bool | Whether the login has been verified (readonly). |
$auth->optionalVerifiedTimestamp | ?CalendarDateTimeData | When 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.
| Name | Type | Description |
|---|---|---|
$id | int | The auth record id. |
$memberId | int | The id of the member the login belongs to. |
$authType | string | The auth type, for example Email or Mobile. |
$authLogin | string | The login identifier. |
$verified | bool | Whether the login has been verified. |
$verifiedTimestamp | ?CalendarDateTimeData | When the login was verified, or null. |
Returns MemberAuthData
FromJson
MemberAuthData::FromJson(string $json): MemberAuthData
Build an auth record from its JSON string.
| Name | Type | Description |
|---|---|---|
$json | string | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The member the login belongs to. |
$authLogin | string | The login identifier. |
$authType | string | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The member to read a login for. |
$authType | string | The auth type to read. |
Returns MemberAuthData The matching login record.
GetById
MemberAuthDatabase::GetById(int $authId): MemberAuthData
Get an authentication login record by its id.
| Name | Type | Description |
|---|---|---|
$authId | int | The auth record id. |
Returns MemberAuthData The login record.
GetByMemberId
MemberAuthDatabase::GetByMemberId(int $memberId): array
Get all authentication login records for a member.
| Name | Type | Description |
|---|---|---|
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$authType | string | The auth type to match. |
$authLogin | string | The 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.
| Name | Type | Description |
|---|---|---|
$authType | string | The auth type to match. |
$authLogin | string | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The member to read an email for. |
$fallbackEmail | string | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The member to read a login for. |
$authType | string | The 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.
| Name | Type | Description |
|---|---|---|
$authId | int | The 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.
| Name | Type | Description |
|---|---|---|
$authLogin | string | The login identifier. |
$authType | string | The auth type, for example Email or Mobile. |
$password | string | The 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
| Property | Type | Description |
|---|---|---|
$code->permalink | PermalinkData | The code's permalink (readonly). |
$code->authId | int | The auth record the code was issued for (readonly). |
$code->codeTypeName | string | The registered code type name (readonly). |
$code->code | string | The code value entered by the member (readonly). |
$code->lastSendTimestamp | int | Unix time the code was last sent (readonly). |
$code->expiryTimestamp | int | Unix time the code expires (readonly). |
$code->memberId | int | The member the code belongs to (readonly). |
$code->status | int | The code status; see the MemberCodeDatabase status constants (readonly). |
__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.
| Name | Type | Description |
|---|---|---|
$permalink | PermalinkData | The code's permalink. |
$authId | int | The auth record the code was issued for. |
$codeTypeName | string | The registered code type name. |
$code | string | The code value. |
$lastSendTimestamp | int | Unix time the code was last sent. |
$expiryTimestamp | int | Unix time the code expires. |
$memberId | int | The member the code belongs to. |
$status | int | The 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
| Constant | Value | Description |
|---|---|---|
MemberCodeDatabase::STATUS_UNUSED | 1 | The code has not yet been used. |
MemberCodeDatabase::STATUS_USED | 2 | The code has been used. |
MemberCodeDatabase::DEFAULT_EXPIRY | 60*60 | The default code lifetime in seconds (one hour). |
MemberCodeDatabase::DEFAULT_EMAIL_DELAY_SECONDS | 5 | The default minimum delay between email code sends. |
GetById
MemberCodeDatabase::GetById(int $codeId): MemberCodeData
Fetch a code by id, without checking its status or expiry.
| Name | Type | Description |
|---|---|---|
$codeId | int | The 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.
| Name | Type | Description |
|---|---|---|
$codeTypeName | string | The registered code type name. |
$authId | int | The auth record the code was issued for. |
$memberId | int | The member the code belongs to. |
Returns MemberCodeData The active code record.
GetByPermalink
MemberCodeDatabase::GetByPermalink(PermalinkData $permalink): MemberCodeData
Fetch a code by its permalink, without checking its status or expiry.
| Name | Type | Description |
|---|---|---|
$permalink | PermalinkData | The 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.
| Name | Type | Description |
|---|---|---|
$codeTypeName | string | The registered code type name. |
$authId | int | The auth record the code is issued for. |
$memberId | int | The member the code belongs to. |
$expirySeconds | int | How 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.
| Name | Type | Description |
|---|---|---|
$allowedChars | string | The characters the code may contain. |
$length | int | The 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.
| Name | Type | Description |
|---|---|---|
$codeData | MemberCodeData | The code to update. |
$delaySeconds | int | The 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.
| Name | Type | Description |
|---|---|---|
$codeData | MemberCodeData | The code being validated. |
$code | string | The 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.
Permalink
MemberCodeRoute::Permalink(Callable $routeCallback): void
Register the member_code permalink type; on a match the resolved MemberCodeData is passed to the callback.
| Name | Type | Description |
|---|---|---|
$routeCallback | Callable | Called 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
| Property | Type | Description |
|---|---|---|
$member->id | int | The member id (readonly). |
$member->added | CalendarDateTimeData | When the member was added (readonly). |
$member->deleted | bool | Whether the member is soft-deleted (readonly). |
$member->optionalDeletedTimestamp | ?CalendarDateTimeData | When the member was deleted, or null (readonly, field named deletedTimestamp). |
__construct
new MemberData(int $id = 0, CalendarDateTimeData $added = new CalendarDateTimeData(), bool $deleted = false, ?CalendarDateTimeData $deletedTimestamp = null)
Create a member record.
| Name | Type | Description |
|---|---|---|
$id | int | The member id. |
$added | CalendarDateTimeData | When the member was added. |
$deleted | bool | Whether the member is soft-deleted. |
$deletedTimestamp | ?CalendarDateTimeData | When 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$codeTypeName | string | The code type name. |
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$email | string | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$authType | string | The auth type, for example Email or Mobile. |
$authLogin | string | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The member to check. |
$moduleName | string | The module that owns the feature. |
$featureName | string | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$code | MemberCodeData | The 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.
| Name | Type | Description |
|---|---|---|
$codeData | MemberCodeData | The 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.
| Name | Type | Description |
|---|---|---|
$code | MemberCodeData | The 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.
| Name | Type | Description |
|---|---|---|
$codeData | MemberCodeData | The 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
| Property | Type | Description |
|---|---|---|
$password->id | int | The password record id (readonly). |
$password->memberId | int | The member the password belongs to (readonly). |
$password->passwordHashed | string | The stored password hash (readonly). |
$password->addedTimestamp | CalendarDateTimeData | When 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.
| Name | Type | Description |
|---|---|---|
$id | int | The password record id. |
$memberId | int | The member the password belongs to. |
$passwordHashed | string | The stored password hash. |
$addedTimestamp | CalendarDateTimeData | When the password was added. |
Returns MemberPasswordData
FromJson
MemberPasswordData::FromJson(string $json): MemberPasswordData
Build a password record from its JSON string.
| Name | Type | Description |
|---|---|---|
$json | string | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | ?int | A 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The member the password belongs to. |
$password | string | The 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.
| Name | Type | Description |
|---|---|---|
$passwordId | int | The password record id. |
Returns MemberPasswordData The password record.
GetByMemberId
MemberPasswordDatabase::GetByMemberId(int $memberId): array
List all password records for a member.
| Name | Type | Description |
|---|---|---|
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$start | int | The offset of the first record. |
$count | int | The maximum number of records to return. |
$memberId | ?int | A 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The member to check. |
$password | string | The 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.
| Name | Type | Description |
|---|---|---|
$passwordId | int | The password record to update. |
$password | string | The 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.
LoggedIn
MemberRoute::LoggedIn(callable $routes): void
Define the routes only for a logged-in member, and always during the scan pass.
| Name | Type | Description |
|---|---|---|
$routes | callable | The 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.
| Name | Type | Description |
|---|---|---|
$routes | callable | The block of route definitions. |
Returns void
MemberSecurity
Enforce that a member is logged in. Unlike MemberRoute, this throws when the requirement is not met.
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.
| Name | Type | Description |
|---|---|---|
$moduleName | string | The module that owns the feature. |
$featureName | string | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$codePermalink | PermalinkData | The code's permalink. |
Returns string The code-entry page URL.
CodeLink
MemberUrl::CodeLink(PermalinkData $codePermalink, string $code): string
The URL that enters a specific code for a code permalink directly.
| Name | Type | Description |
|---|---|---|
$codePermalink | PermalinkData | The code's permalink. |
$code | string | The 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.
| Name | Type | Description |
|---|---|---|
$methodName | ?string | An 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.