Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

142 строки
4.5KB

  1. <%
  2. ' Auto-generated Controller: OrderApi
  3. ' Generated on 7/28/2026 2:56:29 PM
  4. ' Generator: generateController.vbs v1.0
  5. '
  6. ' Remember to:
  7. ' 1. Add to app/controllers/autoload_controllers.asp
  8. ' 2. Register in core/lib.ControllerRegistry.asp
  9. ' 3. Add routes in public/Default.asp
  10. Class OrderApiController_Class
  11. Private m_useLayout
  12. Private m_title
  13. Private Sub Class_Initialize()
  14. m_useLayout = False ' this controller returns JSON only, never the shared HTML layout
  15. m_title = "OrderApi"
  16. End Sub
  17. Public Property Get useLayout
  18. useLayout = m_useLayout
  19. End Property
  20. Public Property Let useLayout(v)
  21. m_useLayout = v
  22. End Property
  23. Public Property Get Title
  24. Title = m_title
  25. End Property
  26. Public Property Let Title(v)
  27. m_title = v
  28. End Property
  29. '-------------------------------------------------------------------------------------------------------------------
  30. ' POST: accept the completed SurveyJS order-details form (as JSON) for the order matching ?token=
  31. '-------------------------------------------------------------------------------------------------------------------
  32. Public Sub SubmitOrderDetails()
  33. Response.ContentType = "application/json"
  34. If Request.ServerVariables("REQUEST_METHOD") <> "POST" Then
  35. WriteJsonError "405 Method Not Allowed", "This endpoint only accepts POST."
  36. Exit Sub
  37. End If
  38. Dim token, order
  39. token = Trim(Request.QueryString("token"))
  40. Set order = Nothing
  41. If Len(token) > 0 Then Set order = OrdersRepository().FindByToken(token)
  42. If order Is Nothing Then
  43. WriteJsonError "404 Not Found", "Order not found."
  44. Exit Sub
  45. End If
  46. If order("TokenExpiresAt") < Now() Then
  47. WriteJsonError "410 Gone", "This order link has expired. Please request a new one."
  48. Exit Sub
  49. End If
  50. Dim csrfToken : csrfToken = Request.ServerVariables("HTTP_X_CSRF_TOKEN")
  51. If Not HTMLSecurity().IsValidAntiCSRFToken("Order.Continue", csrfToken) Then
  52. WriteJsonError "403 Forbidden", "Your form session expired. Please refresh the page and try again."
  53. Exit Sub
  54. End If
  55. Dim turnstileToken : turnstileToken = Request.ServerVariables("HTTP_X_TURNSTILE_TOKEN")
  56. If Not VerifyTurnstileToken(turnstileToken, Request.ServerVariables("REMOTE_ADDR")) Then
  57. WriteJsonError "403 Forbidden", "Verification challenge failed. Please refresh the page and try again."
  58. Exit Sub
  59. End If
  60. Dim answers
  61. On Error Resume Next
  62. json().loadJSON GetRawJsonFromRequest()
  63. If Err.Number <> 0 Then
  64. Err.Clear
  65. On Error GoTo 0
  66. WriteJsonError "400 Bad Request", "Could not read the submitted form data."
  67. Exit Sub
  68. End If
  69. On Error GoTo 0
  70. Set answers = json().data
  71. Dim validationError : validationError = ValidateOrderDetailsAnswers(answers)
  72. If Len(validationError) > 0 Then
  73. WriteJsonError "400 Bad Request", validationError
  74. Exit Sub
  75. End If
  76. Dim model : Set model = New POBO_OrderDetails
  77. On Error Resume Next
  78. MapOrderDetailsAnswers model, answers
  79. model.SubmittedAt = Now()
  80. If Err.Number <> 0 Then
  81. Err.Clear
  82. On Error GoTo 0
  83. WriteJsonError "400 Bad Request", "The submitted data could not be processed. Please check your entries and try again."
  84. Exit Sub
  85. End If
  86. On Error GoTo 0
  87. On Error Resume Next
  88. OrderDetailsRepository().SaveForOrder order("OrderID"), model
  89. If Err.Number <> 0 Then
  90. Err.Clear
  91. On Error GoTo 0
  92. WriteJsonError "500 Internal Server Error", "Could not save your order details. Please try again."
  93. Exit Sub
  94. End If
  95. On Error GoTo 0
  96. ' Best-effort: the order is already safely persisted at this point, so an SMTP hiccup
  97. ' should not turn a successful submission into a failed one.
  98. OrderMailer().SendOrderDetailsEmail order, model
  99. Response.Write "{""success"":true}"
  100. End Sub
  101. End Class
  102. ' Singleton instance
  103. Dim OrderApiController_Class__Singleton
  104. Function OrderApiController()
  105. If IsEmpty(OrderApiController_Class__Singleton) Then
  106. Set OrderApiController_Class__Singleton = New OrderApiController_Class
  107. End If
  108. Set OrderApiController = OrderApiController_Class__Singleton
  109. End Function
  110. %>

Powered by TurnKey Linux.