選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

143 行
5.6KB

  1. <%
  2. Class RequestOrderController_Class
  3. Private m_useLayout
  4. Private m_title
  5. Private Sub Class_Initialize()
  6. m_useLayout = True
  7. m_title = "Request an Order"
  8. End Sub
  9. Public Property Get useLayout
  10. useLayout = m_useLayout
  11. End Property
  12. Public Property Let useLayout(v)
  13. m_useLayout = v
  14. End Property
  15. Public Property Get Title
  16. Title = m_title
  17. End Property
  18. Public Property Let Title(v)
  19. m_title = v
  20. End Property
  21. '-------------------------------------------------------------------------------------------------------------------
  22. ' GET: show the "request an order" form (email + jurisdiction number)
  23. '-------------------------------------------------------------------------------------------------------------------
  24. Public Sub Index()
  25. Dim formValues, emailValue, jurisdictionValue, csrfToken
  26. Set formValues = FormCache().DeserializeForm("RequestOrder")
  27. FormCache().ClearForm "RequestOrder"
  28. emailValue = ""
  29. jurisdictionValue = ""
  30. If Not (formValues Is Nothing) Then
  31. If formValues.Exists("Email") Then emailValue = formValues("Email")
  32. If formValues.Exists("JurisdictionNumber") Then jurisdictionValue = formValues("JurisdictionNumber")
  33. End If
  34. csrfToken = HTMLSecurity().GetAntiCSRFToken("RequestOrder")
  35. %>
  36. <!--#include file="../views/RequestOrder/index.asp" -->
  37. <%
  38. End Sub
  39. '-------------------------------------------------------------------------------------------------------------------
  40. ' POST: validate submission, create the order record, email a continuation link
  41. '-------------------------------------------------------------------------------------------------------------------
  42. Public Sub Create()
  43. MVC.RequirePost
  44. Dim csrfToken : csrfToken = Request.Form("csrf_token")
  45. If Not HTMLSecurity().IsValidAntiCSRFToken("RequestOrder", csrfToken) Then
  46. HTMLSecurity().ClearAntiCSRFToken "RequestOrder"
  47. Flash().AddError "Your form session expired. Please try again."
  48. Response.Redirect Routes().AppURL & "request-order"
  49. Exit Sub
  50. End If
  51. HTMLSecurity().ClearAntiCSRFToken "RequestOrder"
  52. Dim email, jurisdictionNumber
  53. email = Trim(Request.Form("Email"))
  54. jurisdictionNumber = Trim(Request.Form("JurisdictionNumber"))
  55. Dim errorList() : ReDim errorList(-1)
  56. If Not IsValidEmail(email) Then AddValidationError errorList, "Please enter a valid email address."
  57. If Len(jurisdictionNumber) = 0 Then
  58. AddValidationError errorList, "Please enter your jurisdiction number."
  59. ElseIf Not IsValidJurisdictionNumber(jurisdictionNumber) Then
  60. AddValidationError errorList, "That jurisdiction number could not be verified."
  61. End If
  62. If UBound(errorList) >= 0 Then
  63. Dim i
  64. For i = 0 To UBound(errorList)
  65. Flash().AddError errorList(i)
  66. Next
  67. FormCache().SerializeForm "RequestOrder", Request.Form
  68. Response.Redirect Routes().AppURL & "request-order"
  69. Exit Sub
  70. End If
  71. Dim token : token = OrdersRepository().CreateOrder(email, jurisdictionNumber)
  72. SendOrderContinuationEmail email, token
  73. Flash().Success = "Check your email for a link to continue your order."
  74. Response.Redirect Routes().AppURL & "request-order"
  75. End Sub
  76. '-------------------------------------------------------------------------------------------------------------------
  77. ' Private helpers
  78. '-------------------------------------------------------------------------------------------------------------------
  79. Private Function IsValidEmail(email)
  80. Dim re
  81. Set re = New RegExp
  82. re.Pattern = "^[^\s@]+@[^\s@]+\.[^\s@]+$"
  83. re.IgnoreCase = True
  84. IsValidEmail = re.Test(email)
  85. End Function
  86. Private Sub AddValidationError(ByRef errorList, msg)
  87. ReDim Preserve errorList(UBound(errorList) + 1)
  88. errorList(UBound(errorList)) = msg
  89. End Sub
  90. Private Sub SendOrderContinuationEmail(email, token)
  91. Dim continueUrl
  92. continueUrl = Routes().AppURL & "order/continue?token=" & Server.URLEncode(token)
  93. Dim smtpPort : smtpPort = GetAppSetting("SmtpPort")
  94. If Not IsNumeric(smtpPort) Then smtpPort = 25
  95. Dim mail : Set mail = CDOEmail()
  96. mail.SMTPServer = GetAppSetting("SmtpServer")
  97. mail.SMTPPort = CInt(smtpPort)
  98. mail.SMTPUsername = GetAppSetting("SmtpUsername")
  99. mail.SMTPPassword = GetAppSetting("SmtpPassword")
  100. mail.SMTPUseSSL = (LCase(GetAppSetting("SmtpUseSSL")) = "true")
  101. mail.From = GetAppSetting("SmtpFromAddress")
  102. mail.Subject = "Continue your Purple Envelope order"
  103. mail.IsBodyHTML = True
  104. mail.Body = "<p>Click the link below to continue your order:</p>" & _
  105. "<p><a href=""" & H(continueUrl) & """>" & H(continueUrl) & "</a></p>" & _
  106. "<p>This link expires in " & H(GetAppSetting("OrderTokenExpirationHours")) & _
  107. " hours and can only be used once.</p>"
  108. mail.AddRecipient "To", email
  109. mail.Send
  110. End Sub
  111. End Class
  112. Dim RequestOrderController_Class__Singleton
  113. Function RequestOrderController()
  114. If IsEmpty(RequestOrderController_Class__Singleton) Then
  115. Set RequestOrderController_Class__Singleton = New RequestOrderController_Class
  116. End If
  117. Set RequestOrderController = RequestOrderController_Class__Singleton
  118. End Function
  119. %>

Powered by TurnKey Linux.