Last active
March 9, 2023 16:55
-
-
Save zuzannamj/1bed965165aaf6a805d973d0a108b48c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%[ | |
IF RequestParameter("submitted") == true THEN | |
/* generate an OPT */ | |
set @num1 = 1000 | |
set @num2 = 9999 | |
set @OTP = random(@num1, @num2) | |
/* send a triggered email containing the opt */ | |
SET @ts = CreateObject("TriggeredSend") | |
SET @tsDef = CreateObject("TriggeredSendDefinition") | |
SET @ts_extkey = "43099" /* replace with ID of your Triggered Send */ | |
SET @ts_email = RequestParameter("email") | |
SetObjectProperty(@tsDef, "CustomerKey", @ts_extkey) | |
SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef) | |
SET @ts_sub = CreateObject("Subscriber") | |
SetObjectProperty(@ts_sub, "EmailAddress", @ts_email) | |
SetObjectProperty(@ts_sub, "SubscriberKey", @ts_email) | |
SET @attr = CreateObject("Attribute") | |
SetObjectProperty(@attr, "Name", "OTP") | |
SetObjectProperty(@attr, "Value", @OTP) | |
AddObjectArrayItem(@ts_sub, "Attributes", @attr) | |
AddObjectArrayItem(@ts, "Subscribers", @ts_sub) | |
SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode) | |
/* display a form where subscriber submits otp */ | |
]%% | |
<form action="%%=RequestParameter('PAGEURL')=%%" method="post"> | |
<label>OTP: </label><input type="text" name="OTP" required=""><br> | |
<input name="email" type="hidden" value="%%=RequestParameter("email")=%%"><br> | |
<input name="submittedOTP" type="hidden" value="true"><br> | |
<input type="submit" value="Submit"> | |
</form> | |
%%[ | |
ELSEIF RequestParameter("submittedOTP") == true THEN | |
SET @OTP = RequestParameter('OTP') | |
SET @email = RequestParameter("email") | |
/* check OTP against the DE */ | |
set @rows = LookupOrderedRows("OTP", 1, "SentDate desc", "EmailAddress", @email) | |
if @rowCount > 0 then | |
set @row = row(@rows, 1) | |
set @deOTP = field(@row,"OTP") | |
endif | |
if @otp == @deOTP then | |
]%% | |
OTP verified | |
%%[ else ]%% | |
OTP not vverified | |
%%[ endif ]%% | |
%%[ ELSE ]%% | |
<form action="%%=RequestParameter('PAGEURL')=%%" method="post"> | |
<label>Email: </label><input type="text" name="email" required=""><br> | |
<input name="submitted" type="hidden" value="true"><br> | |
<input type="submit" value="Submit"> | |
</form> | |
%%[ ENDIF ]%% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment