Guest User

Untitled

a guest
Nov 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. <form action="%%=RequestParameter('PAGEURL')=%%" id="subscribeForm"
  2. name="subscribeForm" method="post">
  3. <table cellpadding="0" cellspacing="0" border="0">
  4. <tr>
  5. <td height="60" width="250">
  6. <font face="Verdana" size="2">Email</font>*<br />
  7. <input type="text" id="EmailAddress" name="EmailAddress"></td>
  8. </tr>
  9. <tr>
  10. <td height="60" colspan="2">
  11. <input name="Submit" class="submit" type="submit" value="Submit">
  12. </td>
  13. <td></td>
  14. </tr>
  15. </table>
  16. </form>
  17.  
  18. <script language="javascript" runat="server">
  19. Platform.Load("Core","1");
  20. try{
  21. </script>
  22.  
  23. %%[ var @subscriberKey, @emailAddress, @url, @body,
  24. @httppost,@apiid,@apistatusCode,@apiresponse,@apitoken,
  25. @accessToken, @now, @callstatus, @response, @errorMsg
  26.  
  27. set @emailAddress = ""
  28. set @httppost = ""
  29.  
  30. if RequestParameter("Submit") == "Submit" then
  31.  
  32. set @emailAddress = RequestParameter("EmailAddress")
  33.  
  34. set @body = CONCAT('{"email": ', CONCAT('"', @emailAddress,
  35. '",'),'"validators": ', '["SyntaxValidator",', '"MXValidator",',
  36. '"ListDetectiveValidator"',']}')
  37.  
  38. set @apitoken = Lookup('AccessToken','AccessToken','id',1)
  39. set @accessToken = CONCAT('BEARER ', @apitoken)
  40.  
  41. set @url = "https://www.exacttargetapis.com/address/v1/validateEmail"
  42.  
  43. set @httppost = HTTPPost2(@url, "application/json", @body, true,
  44. @callstatus, @response, 'Authorization', @accessToken)
  45.  
  46. RaiseError(CONCAT('The error experienced was: ',@httppost),false)
  47.  
  48. endif
  49. ]%%
  50.  
  51. <script language="javascript" runat="server">
  52. } catch (ex) {
  53. Variable.SetValue("@errorMsg", Stringify(ex))
  54. </script>
  55.  
  56. %%[
  57.  
  58. if RequestParameter("Submit") == "Submit" then
  59.  
  60. var @regEx1, @resultOfRegex1
  61.  
  62. set @errorMsg = Substring(@errorMsg,2, Subtract(Length(@errorMsg),2))
  63.  
  64. set @regEx1 = '(401).+(Unauthorized)'
  65.  
  66. set @resultOfRegex1 = RegExMatch(@errorMsg, @regEx1, 0)
  67.  
  68. if Length(@resultOfRegex1) > 0 THEN
  69.  
  70. set @now = Now()
  71.  
  72. /* part A - Refresh AccessToken */
  73.  
  74. set @apiid = '{"clientId": "MYCLIENTIDGOESHERE",
  75. "clientSecret":"MYCLIENTSECRETGOESHERE"}'
  76. set @httppost =
  77. HTTPPost2("https://auth.exacttargetapis.com/v1/requestToken",
  78. "application/json", @apiid,false,@apistatusCode,@apiresponse)
  79. set @apitoken = Substring(@apistatusCode,17,24)
  80. set @accessToken = CONCAT('BEARER ', @apitoken)
  81.  
  82. set @httppost = HTTPPost2(@url, "application/json",
  83. @body, true, @callstatus, @response, 'Authorization', @accessToken)
  84.  
  85. UpsertData("AccessToken",1,"id","1","AccessToken",@apitoken)
  86. UpsertData("AccessToken",1,"id","1","Last Updated",@now)
  87.  
  88. /* part B - Validate EmailAddress */
  89.  
  90. set @body = CONCAT('{"email": ', CONCAT('"', @emailAddress,
  91. '",'),'"validators": ', '["SyntaxValidator",', '"MXValidator",',
  92. '"ListDetectiveValidator"',']}')
  93.  
  94. set @apitoken = Lookup('AccessToken','AccessToken','id',1)
  95. set @accessToken = CONCAT('BEARER ', @apitoken)
  96.  
  97. set @url = "https://www.exacttargetapis.com/address/v1/validateEmail"
  98.  
  99. set @httppost = HTTPPost2(@url, "application/json",
  100. @body, true, @callstatus, @response, 'Authorization', @accessToken)
  101.  
  102. endif
  103.  
  104. endif
  105.  
  106. ]%%
  107.  
  108. <script language="javascript" runat="server">
  109. }
  110. </script></span>
  111.  
  112. %%[ if RequestParameter("Submit") == "Submit" AND @httppost == 200 then ]%%
  113.  
  114. EmailAddress: <span style="color:darkblue;">%%=v(@emailAddress)=%%</span><br>
  115. body: <span style="color:darkblue;">%%=v(@body)=%%</span><br>
  116. callstatus: <span style="color:darkblue;">%%=v(@callstatus)=%%</span><br>
  117. httppost: <span style="color:darkblue;">%%=v(@httppost)=%%</span><br><br>
  118.  
  119. %%{={{ }}=}%%
  120.  
  121. {{.datasource JSONVar type=variable}}
  122. {{.data}}
  123. { "target" : "@callstatus" }
  124. {{/data}}
  125. {{#if valid == "true"}}
  126. email: <span style="color:green">{{email}}</span><br>
  127. valid: <span style="color:green">{{valid}}</span><br>
  128. {{.else}}
  129. email: <span style="color:red">{{email}}</span><br>
  130. valid: <span style="color:red">{{valid}}</span><br>
  131. failedValidation: <span style="color:red">{{failedValidation}}</span>
  132. {{/if}}
  133. {{/datasource}}
  134.  
  135. %%[ endif ]%%
Add Comment
Please, Sign In to add comment