Smallthoughts

Thoughts on Smalltalk

Using email confirmation

You can cause TFLogin to send an email confirmation message and evaluate a block that you provide when the user navigates to the confirmation URL. This feature uses the same mechanism as is used for registration confirmation, username reminders, password resets, and account change confirmations.

The TLPendingUserAction is a subclass of TLUser and is a copy of the user for which the action is being confirmed. The confirm block that you provide is passed the TLPendingUser object. Note that when it is evaluated, the session context will be different than when the pending action was queued.

Here is an example from TLTestApp. Other referenced methods can be seen in the TLTestApp source code.

confirmWithUser
| url userAction |
"Instantiate a TLPendingUserAction object for your
user and provide a one-argument block to be evaluated
when the user confirms."

userAction := TLPendingUserAction
forUser: self session user
onConfirmDo: [ :confirmedAction |
"In our action we will log the user in and set
a flag indicating that they have confirmed."

loginComponent loginUserById: confirmedAction userId.
self testConfirmed: true ].

"Queue the pending user action. It will remain active
for the configured confirmation timeout period. This
method answers the confirmation URL to which the user
must navigate to confirm the action."

url := loginComponent addPendingUserAction: userAction.

"Send a confirmation email to the user."
self
sendTestConfirmationUrl: url
to: self session user email
timeout: (self application
preferenceAt: #confirmationTimeoutMinutes)