Yu-Gi-Oh! Deck Building and Card Inventory Management web interface written in Common Lisp, utilizing HTMX.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

77 linhas
2.3KB

  1. #|
  2. # Contact Form
  3. GET /contact Index
  4. GET /contact/admin Admin Panel
  5. GET /contact/:id View Submission TODO
  6. DELETE /contact Clear All
  7. DELETE /contact/:id Delete By ID
  8. POST /contact New Submission
  9. |#
  10. (in-package #:cl-deck-builder2.web)
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12. (defun render-feedback (&optional (tpl #P"contact/index.html"))
  13. (render-with-env tpl (append
  14. (list :active "/contact")
  15. (auth (:admin)
  16. (list :feedback (select-feedback))))))
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18. (defroute ("/contact" :method :GET) ()
  19. "Contact Form Index Page"
  20. (v:info :contact "GET /contact")
  21. (with-logged-in-user
  22. (render-feedback)))
  23. (defroute ("/contact/admin" :method :GET) ()
  24. "Contact Form Admin Panel"
  25. (with-logged-in-user
  26. (render-feedback #P"contact/admin.html")))
  27. (defroute ("/contact" :method :DELETE) ()
  28. "Delete *ALL* FEEDBACK."
  29. (v:info :contact "DELETE /contact")
  30. (auth (:admin)
  31. (progn
  32. (delete-from 'feedback)
  33. (flash-message (_ "Feedback cleared."))
  34. (render-feedback #P"contact/list.html"))
  35. (flash-error (_ "Something went wrong. Try again?"))))
  36. (defroute ("/contact/:id/delete" :method :DELETE) (&key id)
  37. "Delete FEEDBACK with matching ID."
  38. (auth (:admin)
  39. (handler-case
  40. (ratify:with-parsed-forms
  41. ((:integer id))
  42. (delete-by-values 'feedback :id id))
  43. (ratify:combined-error (e)
  44. (flash-error e)))))
  45. (defroute ("/contact" :method :POST) (&key _parsed)
  46. "User Submit Feedback POST Route. Login Required."
  47. (v:info :contact "POST /contact => ~a" _parsed)
  48. (with-logged-in-user
  49. (let ((user (find-dao 'user :email (user-name)))
  50. (body (query-param "query" _parsed)))
  51. (handler-case
  52. (ratify:with-parsed-forms
  53. ((:string body))
  54. (if (ignore-errors
  55. (create-feedback user body))
  56. (flash-message (_ "Thanks! We got your message."))
  57. (flash-error (_ "Something went wrong. Try again?"))))
  58. (ratify:combined-error (e)
  59. (flash-error e))))
  60. (redirect "/contact")))