CoolCMS API

ManageKeyTrait

Provides a "manage" link instead of a readable password in the insert e-mail of a record created without an account: Bazaar advert, Comcat company profile, Discussion post ({@see ManageKeyAwareInterface}).

The key rules are in AdvertManageKey.

  • self::issueManageKey() issues the key for a record without an owner but with a password (for a guest post the random secret set on insert) after the insert commit (completedSave → the module's e-mail trait); only a digest and the expiry go to the database, the readable key only into the link,
  • self::redeemManageKey() verifies the key for the front end (edit?id=…&manageKey=…) through the internal Api action redeemManageKey; on a match the front end opens an edit session as after entering the password. The key is not consumed (valid until it expires) and stops working when the password changes.
Tags
requires

Api manager — find(int, array): ?object, updateColumns(int|array, array): Result

Table of Contents

Methods

redeemManageKey()  : Result
Returns `OK` when the key matches the record and its current password and is still valid. An unknown record, a record with an owner, a wrong or expired key and a key after a password change all return the same code `USER_PASSWORD_RESET_KEY_INVALID`, so the action does not reveal which part did not match.
issueManageKey()  : string|null
Issues the key and returns it in readable form (only for the e-mail link); `null` means the record needs no link or the write failed, and the e-mail then carries a plain edit link (logged-in owner, password, reset).

Methods

redeemManageKey()

Returns `OK` when the key matches the record and its current password and is still valid. An unknown record, a record with an owner, a wrong or expired key and a key after a password change all return the same code `USER_PASSWORD_RESET_KEY_INVALID`, so the action does not reveal which part did not match.

public redeemManageKey(int $recordId, string $key) : Result
Parameters
$recordId : int
$key : string
Return values
Result

issueManageKey()

Issues the key and returns it in readable form (only for the e-mail link); `null` means the record needs no link or the write failed, and the e-mail then carries a plain edit link (logged-in owner, password, reset).

private issueManageKey(ManageKeyAwareInterface $record) : string|null
Parameters
$record : ManageKeyAwareInterface
Return values
string|null
On this page

Search results