<%
Class OrderController_Class
    Private m_useLayout
    Private m_title

    Private Sub Class_Initialize()
        m_useLayout = True
        m_title = "Your 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: verify the token from the emailed link and continue the order.
    ' The order form itself is a placeholder for now - this only confirms the token is valid.
    '-------------------------------------------------------------------------------------------------------------------
    Public Sub Continue()
        Dim token, order, isValid, csrfToken, municipalityName, turnstileSiteKey
        token = Trim(Request.QueryString("token"))
        isValid = False
        csrfToken = ""
        municipalityName = ""
        turnstileSiteKey = GetAppSetting("TurnstileSiteKey")
        Set order = Nothing

        If Len(token) > 0 Then
            Set order = OrdersRepository().FindByToken(token)
            If Not (order Is Nothing) Then
                If IsNull(order("TokenUsedAt")) And order("TokenExpiresAt") >= Now() Then
                    isValid = True
                    OrdersRepository().MarkTokenUsed order("OrderID")
                End If
            End If
        End If

        If isValid Then
            csrfToken = HTMLSecurity().GetAntiCSRFToken("Order.Continue")
            ' Look up the municipality from the same jurisdiction list the number was
            ' already validated against at /request-order - "" means no match (cache empty
            ' or code not found), and the view falls back to a manually-entered field.
            municipalityName = GetJurisdictionName(order("JurisdictionNumber"))
        End If
    %>
    <!--#include file="../views/Order/continue.asp" -->
    <%
    End Sub

End Class

Dim OrderController_Class__Singleton
Function OrderController()
    If IsEmpty(OrderController_Class__Singleton) Then
        Set OrderController_Class__Singleton = New OrderController_Class
    End If
    Set OrderController = OrderController_Class__Singleton
End Function
%>


