|
- <%
- Class RequestOrderController_Class
- Private m_useLayout
- Private m_title
-
- Private Sub Class_Initialize()
- m_useLayout = True
- m_title = "Request an Order"
- End Sub
-
- Public Property Get useLayout
- useLayout = m_useLayout
- End Property
-
- Public Property Let useLayout(v)
- m_useLayout = v
- End Property
-
- Public Property Get Title
- Title = m_title
- End Property
-
- Public Property Let Title(v)
- m_title = v
- End Property
-
- '-------------------------------------------------------------------------------------------------------------------
- ' GET: show the "request an order" form (email + jurisdiction number)
- '-------------------------------------------------------------------------------------------------------------------
- Public Sub Index()
- Dim formValues, emailValue, jurisdictionValue, csrfToken
-
- Set formValues = FormCache().DeserializeForm("RequestOrder")
- FormCache().ClearForm "RequestOrder"
-
- emailValue = ""
- jurisdictionValue = ""
- If Not (formValues Is Nothing) Then
- If formValues.Exists("Email") Then emailValue = formValues("Email")
- If formValues.Exists("JurisdictionNumber") Then jurisdictionValue = formValues("JurisdictionNumber")
- End If
-
- csrfToken = HTMLSecurity().GetAntiCSRFToken("RequestOrder")
- %>
- <!--#include file="../views/RequestOrder/index.asp" -->
- <%
- End Sub
-
- '-------------------------------------------------------------------------------------------------------------------
- ' POST: validate submission, create the order record, email a continuation link
- '-------------------------------------------------------------------------------------------------------------------
- Public Sub Create()
- MVC.RequirePost
-
- Dim csrfToken : csrfToken = Request.Form("csrf_token")
- If Not HTMLSecurity().IsValidAntiCSRFToken("RequestOrder", csrfToken) Then
- HTMLSecurity().ClearAntiCSRFToken "RequestOrder"
- Flash().AddError "Your form session expired. Please try again."
- Response.Redirect Routes().AppURL & "request-order"
- Exit Sub
- End If
- HTMLSecurity().ClearAntiCSRFToken "RequestOrder"
-
- Dim email, jurisdictionNumber
- email = Trim(Request.Form("Email"))
- jurisdictionNumber = Trim(Request.Form("JurisdictionNumber"))
-
- Dim errorList() : ReDim errorList(-1)
- If Not IsValidEmail(email) Then AddValidationError errorList, "Please enter a valid email address."
- If Len(jurisdictionNumber) = 0 Then
- AddValidationError errorList, "Please enter your jurisdiction number."
- ElseIf Not IsValidJurisdictionNumber(jurisdictionNumber) Then
- AddValidationError errorList, "That jurisdiction number could not be verified."
- End If
-
- If UBound(errorList) >= 0 Then
- Dim i
- For i = 0 To UBound(errorList)
- Flash().AddError errorList(i)
- Next
- FormCache().SerializeForm "RequestOrder", Request.Form
- Response.Redirect Routes().AppURL & "request-order"
- Exit Sub
- End If
-
- Dim token : token = OrdersRepository().CreateOrder(email, jurisdictionNumber)
- SendOrderContinuationEmail email, token
-
- Flash().Success = "Check your email for a link to continue your order."
- Response.Redirect Routes().AppURL & "request-order"
- End Sub
-
- '-------------------------------------------------------------------------------------------------------------------
- ' Private helpers
- '-------------------------------------------------------------------------------------------------------------------
- Private Function IsValidEmail(email)
- Dim re
- Set re = New RegExp
- re.Pattern = "^[^\s@]+@[^\s@]+\.[^\s@]+$"
- re.IgnoreCase = True
- IsValidEmail = re.Test(email)
- End Function
-
- Private Sub AddValidationError(ByRef errorList, msg)
- ReDim Preserve errorList(UBound(errorList) + 1)
- errorList(UBound(errorList)) = msg
- End Sub
-
- Private Sub SendOrderContinuationEmail(email, token)
- Dim continueUrl
- continueUrl = Routes().AppURL & "order/continue?token=" & Server.URLEncode(token)
-
- Dim smtpPort : smtpPort = GetAppSetting("SmtpPort")
- If Not IsNumeric(smtpPort) Then smtpPort = 25
-
- Dim mail : Set mail = CDOEmail()
- mail.SMTPServer = GetAppSetting("SmtpServer")
- mail.SMTPPort = CInt(smtpPort)
- mail.SMTPUsername = GetAppSetting("SmtpUsername")
- mail.SMTPPassword = GetAppSetting("SmtpPassword")
- mail.SMTPUseSSL = (LCase(GetAppSetting("SmtpUseSSL")) = "true")
- mail.From = GetAppSetting("SmtpFromAddress")
- mail.Subject = "Continue your Purple Envelope order"
- mail.IsBodyHTML = True
- mail.Body = "<p>Click the link below to continue your order:</p>" & _
- "<p><a href=""" & H(continueUrl) & """>" & H(continueUrl) & "</a></p>" & _
- "<p>This link expires in " & H(GetAppSetting("OrderTokenExpirationHours")) & _
- " hours and can only be used once.</p>"
- mail.AddRecipient "To", email
- mail.Send
- End Sub
-
- End Class
-
- Dim RequestOrderController_Class__Singleton
- Function RequestOrderController()
- If IsEmpty(RequestOrderController_Class__Singleton) Then
- Set RequestOrderController_Class__Singleton = New RequestOrderController_Class
- End If
- Set RequestOrderController = RequestOrderController_Class__Singleton
- End Function
- %>
|