Skip to main content
With the $wsOptIn module, you can implement token-based opt-in processes in the frontend. Typical use cases are email verification, newsletter confirmation, or password reset. In this section, you will learn how to create opt-in links and check token validity.

Module overview

Example / excerpt of $wsOptIn
{{= $wsOptIn | json }}
JSON output
{
  "current": {
    "valid": true,
    "token": "..."
  },
  "createTokenUrl": "ƒ()"
}
Note: ƒ() denotes a function. Variables and methods overview:
VariableTypeDescription
currentmapReturns a map with info about the active token, if one was passed in the request.
validboolReturns true if the passed token is valid.
tokenstringReturns the passed token as text.
createTokenUrl()stringCreates an opt-in URL with a secure token.

Templates

The $wsOptIn module is typically used for account functions such as resetting a password or creating an account.

Variables

$wsOptIn.current

Contains information about the token passed in the current URL. Is null if no token is present in the URL.
{{ if $wsOptIn.current }}
    // Token was passed
{{ /if }}

$wsOptIn.current.valid

Returns true / false if the passed token is valid / invalid.
{{ if $wsOptIn.current.valid }}
    // Token is valid
{{ else }}
    // Token is invalid or expired
{{ /if }}

$wsOptIn.current.token

Returns the passed token.
Token: {{= $wsOptIn.current.token }}

Methods

$wsOptIn.createTokenUrl()

Creates an opt-in URL with a secure token. The token is generated automatically and appended to the specified URL. This URL can then be sent to the customer by email. Signature
$wsOptIn.createTokenUrl(url, tokenName)
Return value
string - URL with appended token parameter.
Parameters
NameTypeRequiredDescription
urlstringyesBase URL to which the token is appended.
tokenNamestringyesName of the token (e.g. "verifyEmail").
Example that creates a URL with token for email verification.
{{= $wsOptIn.createTokenUrl($wsViews.viewUrl('account/verify.htm'), 'verifyEmail') }}

Actions

No actions are available for $wsOptIn.

Examples for data access

After creating a user account in the shop, the user receives an email to confirm their email address, e.g.
<a href="{{= $wsOptIn.createTokenUrl($wsViews.viewUrl('account/emailVerify.htm', {}, 'absolute'), 'verifyEmail') }}">
  Confirm email address
</a>
The confirmation link contains a token that ensures only the recipient can perform the confirmation.
https://www.beispielshop.de/account/emailVerify.htm?token=abc123xyz
When the user clicks the link and the confirmation page (emailVerify.htm) is opened, it checks whether the token is valid. If so, they can complete the verification with a button click.
{{ if $wsOptIn.current }}
    {{ if $wsOptIn.current.valid }}
      Button to confirm
    {{ else }}
      This link is no longer valid.
    {{ /if }}
{{ else }}
    Invalid access to the confirmation page.
{{ /if }}