$wsOptIn module, you implement token-based opt-in processes in the frontend. Typical use cases are confirming an email address, confirming a newsletter subscription, or resetting a password. The token itself is generated by the respective shop action. In the email template, the module appends it to the confirmation link, and on the confirmation page it checks whether the token is still valid.
This section first explains how an opt-in process works and then lists all token names you can use in your email templates. After that, the module’s variables and methods are described in detail.
Module overview
Example / excerpt of$wsOptIn
ƒ() denotes a function.
Variables and methods overview:
How an opt-in link works
An opt-in process always runs in three steps:- The action generates the token: The customer triggers an action, for example
AccountRegisterorNewsletterSubscribe. The action generates a token, stores it under a fixed token name and sends the associated email. - The email template generates the link: In the email template, you call
$wsOptIn.createTokenUrl()with the URL of the confirmation page and exactly this token name. The method appends the token to the URL. - The confirmation page performs the action: When the customer clicks the link, the confirmation page uses
$wsOptIn.current.validto check whether the token is valid. The customer then performs the confirming action, for exampleEmailVerifyorNewsletterSubscribeConfirm.
AcceptInvitation and passwordReset, the validity period of the invitation link from b2b.userInvitation applies, but at least four hours.
Token names
The following tables show which token name is used in which email. The Email column specifies the configuration in which the email template is stored. The Confirming action column lists the action the customer performs with the token on the confirmation page.Tokens from shop actions
An account activation is complete when
AccountActivate activates the account immediately without opt-in or when the customer confirms the opt-in link with AccountActivateOptIn. An email address change is complete when EmailUpdate changes the address immediately without double opt-in or when the customer confirms the change with EmailUpdateOptIn. In both cases, the shop then sends the email with the verifyEmail token.
Tokens from the Admin Interface API
Some endpoints of the Admin Interface API also send emails with opt-in links. This also applies if you trigger the function in the Admin Interface, for example when you invite a customer.
When the email address is changed via the
PUT newsletter/subscriber/{id} method, the confirmSubscribeNewsletter token additionally contains the ID of the existing subscriber. NewsletterSubscribeConfirm then transfers the confirmed address to this subscriber instead of creating a new one. The email template and the token name remain unchanged. For more information, see NewsletterSubscribeConfirm.
The reminder email for open invitations (b2b.userInvitation → reminderEmail) does not generate a token. In its template, createTokenUrl() therefore only returns the URL without a token.
There are two token names for resetting a password. The email from
actions.passwordForgotten uses passwordReset, while the invitation of a new employee account from b2b.subAccounts uses ResetPassword. Both tokens lead to the ResetPassword action. Therefore, make sure to use the correct name in both email templates.Templates
The$wsOptIn module is used in two places. In the email templates, the createTokenUrl() function generates the confirmation link. On the confirmation pages, for example for resetting the password or confirming a new email address, $wsOptIn.current checks the passed token.
Variables
$wsOptIn.current
Contains information about the token passed in the current URL. Isnull if no token is present in the URL.
$wsOptIn.current.valid
Returnstrue if the passed token is valid and the associated action has not yet been performed with this token. If the token is expired, unknown or already used, the variable returns false.
$wsOptIn.current.token
Returns the passed token.Methods
$wsOptIn.createTokenUrl()
Appends an opt-in token to a URL. The method does not generate a token itself. It uses the token that an action generated in the same call under the specified token name. Therefore, use the method in the email template sent by this action. Which action uses which token name is listed under Token names. Signature$wsOptIn.createTokenUrl(url, tokenName)
Return valuestring - URL with appended token.
- If no token with the specified name was generated in the current call, the method returns the URL unchanged.
- If
urlortokenNameis not text, the method returnsnull.
Example that generates a link with token in the email template for verifying the email address.
Actions
No dedicated actions are available for$wsOptIn. The actions for generating or confirming opt-in tokens can be found under Account and Newsletter.
Examples for data access
Confirming the email address via opt-in link
After a customer account is created, theAccountRegister action generates the verifyEmail token and sends an email to confirm the email address. In the template of this email, you generate the confirmation link like this, for example:
emailVerify.htm) is opened, the page checks whether the token is valid. If so, the customer can complete the verification by clicking a button, which performs the EmailVerify action.
