diff options
Diffstat (limited to 'haunt/jakob/dynamic/capabilities')
| -rw-r--r-- | haunt/jakob/dynamic/capabilities/comment-form.scm | 41 | ||||
| -rw-r--r-- | haunt/jakob/dynamic/capabilities/comments.scm | 11 | ||||
| -rw-r--r-- | haunt/jakob/dynamic/capabilities/rsvp.scm | 2 |
3 files changed, 50 insertions, 4 deletions
diff --git a/haunt/jakob/dynamic/capabilities/comment-form.scm b/haunt/jakob/dynamic/capabilities/comment-form.scm index b435089..70e5303 100644 --- a/haunt/jakob/dynamic/capabilities/comment-form.scm +++ b/haunt/jakob/dynamic/capabilities/comment-form.scm @@ -15,19 +15,56 @@ ;;; <http://www.gnu.org/licenses/>. (define-module (jakob dynamic capabilities comment-form) + #:use-module (gcrypt base64) #:use-module (haunt html) #:use-module (ice-9 match) + #:use-module (jakob dynamic captcha) #:use-module (jakob dynamic util) #:use-module (jakob theme) #:use-module (json) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-11) #:use-module (web request) #:use-module (web response) #:use-module (web uri) #:export (get-comment-form)) +(define (render-comment-form slug) + (let-values (((mac solution captcha-image) (new-captcha))) + `((div (@ (id "comment-form")) + (h1 "Comment form") + (form (@ (id "comment-input") (action "/api/comment") (method "post")) + (input (@ (type "text") (name "slug") (hidden #t) (value ,slug))) + (input (@ (type "text") (name "solution") (hidden #t) (value ,solution))) + (input (@ (type "text") (name "solution-mac") (hidden #t) (value ,mac))) + (fieldset + (legend "Commenter Info") + (label (@ (for "name")) "Name:") + (input (@ (type "text") (id "name") (name "name") (required #t) (size 24))) + (label (@ (for "email")) "Email (optional, used for Gravatar):") + (input (@ (type "text") (id "email") (name "email") (size 24))) + (label (@ (for "url")) "Webpage URL (optional):") + (input (@ (type "text") (id "url") (name "url") (size 24)))) + (fieldset + (legend "Comment") + (label (@ (for "subject")) "Subject (optional):") + (input (@ (type "text") (id "subject") (name "subject") (size 24))) + (label (@ (for "comment")) "Comment :") + (textarea (@ (id "coment") (name "comment") (rows 4) (cols 50)))) + (fieldset + (legend "Captcha") + (label (@ (for "captcha")) "Captcha:") + (img (@ (src ,(format #f "data:image/jpeg;charset=utf-8;base64,~a" + (base64-encode captcha-image))))) + (input (@ (type "text") (id "captcha") (name "captcha") (size 24))) + (input (@ (type "submit") (id "submit-form") (value "Submit"))))))))) + (define (get-comment-form request body) "API endpoint handler for querying for the comments on a particular post This is a wrapper around `get-comments-by-slug'." - (values '((content-type . (text/html))) - (sxml->html-string (theme #:content '(p "Hello, world!"))))) + (let* ((path-encoded (uri-path (request-uri request))) + (path (split-and-decode-uri-path path-encoded)) + (slug (last path))) + (values '((content-type . (text/html))) + (sxml->html-string (theme #:content (render-comment-form slug) #:title "Comment prompt"))))) diff --git a/haunt/jakob/dynamic/capabilities/comments.scm b/haunt/jakob/dynamic/capabilities/comments.scm index d4159fa..3e873a6 100644 --- a/haunt/jakob/dynamic/capabilities/comments.scm +++ b/haunt/jakob/dynamic/capabilities/comments.scm @@ -16,6 +16,7 @@ (define-module (jakob dynamic capabilities comments) #:use-module (ice-9 match) + #:use-module (jakob dynamic captcha) #:use-module (jakob dynamic util) #:use-module (json) #:use-module (squee) @@ -75,9 +76,17 @@ This is a wrapper around `get-comments-by-slug'." (define (put-comment request body) "API endpoint handler for submitting a comment" (define (valid-comment? form-data) + (display form-data) (and (assoc "slug" form-data) (assoc "name" form-data) - (assoc "comment" form-data))) + (assoc "comment" form-data) + (assoc "captcha" form-data) + (assoc "solution" form-data) + (assoc "solution-mac" form-data) + (validate-captcha + (assoc-value form-data "captcha") + (assoc-value form-data "solution") + (assoc-value form-data "solution-mac")))) (define (insert-comment form-data) (exec-query conn "INSERT INTO comments (submitted, slug, name, subject, diff --git a/haunt/jakob/dynamic/capabilities/rsvp.scm b/haunt/jakob/dynamic/capabilities/rsvp.scm index c02b758..d7d6fb9 100644 --- a/haunt/jakob/dynamic/capabilities/rsvp.scm +++ b/haunt/jakob/dynamic/capabilities/rsvp.scm @@ -15,7 +15,7 @@ ;;; <http://www.gnu.org/licenses/>. (define-module (jakob dynamic capabilities rsvp) - #:use-module (base64) + #:use-module (gcrypt base64) #:use-module (ice-9 binary-ports) #:use-module (ice-9 match) #:use-module (jakob dynamic util) |