您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

128 行
4.2KB

  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 answers
  56. On Error Resume Next
  57. json().loadJSON GetRawJsonFromRequest()
  58. If Err.Number <> 0 Then
  59. Err.Clear
  60. On Error GoTo 0
  61. WriteJsonError "400 Bad Request", "Could not read the submitted form data."
  62. Exit Sub
  63. End If
  64. On Error GoTo 0
  65. Set answers = json().data
  66. Dim validationError : validationError = ValidateOrderDetailsAnswers(answers)
  67. If Len(validationError) > 0 Then
  68. WriteJsonError "400 Bad Request", validationError
  69. Exit Sub
  70. End If
  71. Dim model : Set model = New POBO_OrderDetails
  72. On Error Resume Next
  73. MapOrderDetailsAnswers model, answers
  74. model.SubmittedAt = Now()
  75. If Err.Number <> 0 Then
  76. Err.Clear
  77. On Error GoTo 0
  78. WriteJsonError "400 Bad Request", "The submitted data could not be processed. Please check your entries and try again."
  79. Exit Sub
  80. End If
  81. On Error GoTo 0
  82. On Error Resume Next
  83. OrderDetailsRepository().SaveForOrder order("OrderID"), model
  84. If Err.Number <> 0 Then
  85. Err.Clear
  86. On Error GoTo 0
  87. WriteJsonError "500 Internal Server Error", "Could not save your order details. Please try again."
  88. Exit Sub
  89. End If
  90. On Error GoTo 0
  91. ' Best-effort: the order is already safely persisted at this point, so an SMTP hiccup
  92. ' should not turn a successful submission into a failed one.
  93. OrderMailer().SendOrderDetailsEmail order, model
  94. Response.Write "{""success"":true}"
  95. End Sub
  96. End Class
  97. ' Singleton instance
  98. Dim OrderApiController_Class__Singleton
  99. Function OrderApiController()
  100. If IsEmpty(OrderApiController_Class__Singleton) Then
  101. Set OrderApiController_Class__Singleton = New OrderApiController_Class
  102. End If
  103. Set OrderApiController = OrderApiController_Class__Singleton
  104. End Function
  105. %>

Powered by TurnKey Linux.