Commit 790c49b3 authored by Andrew Danger Lyon's avatar Andrew Danger Lyon
Browse files

adding endpoint to accept electronic signatures from contributing page (icle/ecla)

parent ad0a1fd0
......@@ -60,6 +60,7 @@
(defparameter *public-actions*
`((:post . ,(concatenate 'string *api-path* "/users"))
(:post . ,(concatenate 'string *api-path* "/log/error"))
(:post . "/cla/sign")
(:get . ,(cl-ppcre:create-scanner (concatenate 'string *api-path* "/invites/codes/([0-9a-f-]+)"))))
"A list of public resources/actions that do not require authentication.")
......@@ -321,6 +321,15 @@
"Pretty printer for JSON (mainly for database results)."
(to-json db-result :indent 2))
(defmacro with-sock ((sockvar &key db) &body body)
`(let (,sockvar)
(chain (db-sock :db ,db)
(:then (x)
(setf ,sockvar x)
(progn ,@body))
(when sock (r:disconnect sock))))))
(defmacro with-test (&body body)
"Makes testing async functions easier by abstracting an extremely common
(in-package :turtl)
(defvalidator validate-cla
(("id" :type id :required t)
("type" :type string :required t)
("entity" :type string)
("fullname" :type string :required t)
("email" :type string :required t)
("address1" :type string :required t)
("address2" :type string)
("city" :type string :required t)
("state" :type string)
("zip" :type string)
("country" :type string :required t)
("phone" :type string :required t)
("github" :type string :required t)
("sign" :type string :required t)))
(adefun cla-sign (cla-data)
"Sign the CLA."
(unless (string= (hget cla-data '("sign")) "I AGREE")
(error "Please type \"I AGREE\" into the signature field."))
(let ((type (gethash "type" cla-data))
(entity (or (gethash "entity" cla-data) "")))
(when (and (string= type "ecla")
(string= entity ""))
(error "Please enter the Company/Organization/Entity name")))
(add-id cla-data)
(validate-cla (cla-data)
(with-sock (sock :db "company")
(alet* ((query (r:r (:insert
(:table "cla")
(nil (r:run sock query)))
......@@ -15,6 +15,51 @@
(defroute (:post "/cla/sign") (req res)
"Someone wants to sign our CLA! What a glorious day this is."
(let* ((redirect-err (post-var req "redirect-err"))
(redirect-err (if (or (not redirect-err)
(string= redirect-err ""))
(alet* ((fields (list "type"
(redirect (post-var req "redirect"))
(redirect (if (or (not redirect)
(string= redirect ""))
(data (let ((hash (hash)))
(dolist (field fields)
(setf (gethash field hash) (post-var req field)))
(nil (cla-sign data)))
(send-response res
:status 302
:headers (list :location redirect)
:body "Thanks for signing! Redirecting..."))
(error (e)
(vom:error "Caught error: ~a" e)
(print-backtrace e)
(unless (wookie:response-finished-p res)
(unless (as:socket-closed-p (get-socket res))
(send-response res
:status 302
:headers (list :location redirect-err)
:body "There was an error processing your signature. Redirecting.")))))))
(defroute (:* "/api/.+") (req res)
"Any /api/* route that lands here wasn't caught by our controllers. Send the
client a nice 404 and be done with it."
......@@ -55,7 +55,8 @@
(:file "admin")
(:file "analytics")
(:file "feedback")
(:file "promo")))
(:file "promo")
(:file "cla")))
(:file "init" :depends-on (lib "crypto" "errors" "cron" "config/schema" models))
(:module controllers
:depends-on ("init" "errors" lib models "package")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment