MessageGuestEditTrait
Editing a guest post through the "Manage post" link from the insert e-mail (`edit?id=…&manageKey=…`), the same mechanism as an advert without an account (Bazaar `EditAdvertFormTrait` + `AdvertPasswordResetFormTrait::redeemManageKeyFromLink()`).
- The Api verifies the key (
:Api:Discussion:Message:redeemManageKey: digest, 7 days, bound to the post secretMessage::$password). A valid key opens an edit session[id, secret, expiry]in the session (AdvertAccessSession); both outcomes redirect without the key, so it stays out of the browser history and the Referer header. - Every request re-checks the session against the secret loaded from the DB and only then issues the edit capability for the Api (CapabilityTokenIssuer); a changed secret revokes the session.
- A post has no password form: after the session or the link expires, the guest cannot edit any more.
Tags
Table of Contents
Constants
- guestEditSessionExpiration : int = 7200
- Length of the edit session opened by the link, in seconds (same as an advert after the password).
- guestEditSessionSection : string = 'front.discussion.message.edit'
Properties
- $capabilityTokenIssuer : CapabilityTokenIssuer
- Issuer of the capability token for the Api layer (see {@see self::hasGuestEditAccess()}).
Methods
- grantMessageEditCapability() : void
- The token is minted again on every request from the verified session state and never stored.
- grantMessageEditCapabilityFromSession() : void
- Issues the capability from the session before the post is loaded, so `get` for editing returns the guest's own e-mail unmasked. The Api verifies it itself (fingerprint of the secret from the DB), so a stale session row opens nothing; {@see self::hasGuestEditAccess()} stays decisive for access.
- guestEditAccess() : AdvertAccessSession
- hasGuestEditAccess() : bool
- Returns whether this visitor holds a valid edit session for the post. The session row must match the secret of the post loaded from the DB and must not be expired; otherwise it is revoked.
- redeemManageKeyFromLink() : void
- Handles the "Manage post" link: a valid key opens the edit session, an invalid or expired one gives a message (the edit then ends on "permission denied"). Redirects without the key either way.
Constants
guestEditSessionExpiration
Length of the edit session opened by the link, in seconds (same as an advert after the password).
private
int
guestEditSessionExpiration
= 7200
guestEditSessionSection
private
string
guestEditSessionSection
= 'front.discussion.message.edit'
Properties
$capabilityTokenIssuer
Issuer of the capability token for the Api layer (see {@see self::hasGuestEditAccess()}).
public
CapabilityTokenIssuer
$capabilityTokenIssuer
Attributes
- #[Inject]
Methods
grantMessageEditCapability()
The token is minted again on every request from the verified session state and never stored.
private
grantMessageEditCapability(int $messageId, string $secret, int $expiration) : void
Parameters
- $messageId : int
- $secret : string
- $expiration : int
grantMessageEditCapabilityFromSession()
Issues the capability from the session before the post is loaded, so `get` for editing returns the guest's own e-mail unmasked. The Api verifies it itself (fingerprint of the secret from the DB), so a stale session row opens nothing; {@see self::hasGuestEditAccess()} stays decisive for access.
private
grantMessageEditCapabilityFromSession(int $messageId) : void
Parameters
- $messageId : int
guestEditAccess()
private
guestEditAccess() : AdvertAccessSession
Return values
AdvertAccessSessionhasGuestEditAccess()
Returns whether this visitor holds a valid edit session for the post. The session row must match the secret of the post loaded from the DB and must not be expired; otherwise it is revoked.
private
hasGuestEditAccess(Message $message) : bool
IMPORTANT: the capability is issued only after the comparison with the fresh secret, so changing it revokes every open edit session at once.
Parameters
- $message : Message
Return values
boolredeemManageKeyFromLink()
Handles the "Manage post" link: a valid key opens the edit session, an invalid or expired one gives a message (the edit then ends on "permission denied"). Redirects without the key either way.
private
redeemManageKeyFromLink(int $messageId) : void
Parameters
- $messageId : int