Skip to content
Snippets Groups Projects
Commit bdfae5d4 authored by Cam Saul's avatar Cam Saul
Browse files

`req`

parent 02fa1c72
Branches
Tags
No related merge requests found
......@@ -206,12 +206,16 @@
`(defmethod arg-annotation-fn ~(keyword annotation-name) [~'_ ~binding]
`(do ~~@body)))
;; `required` just calls require-params
(defannotation required [param]
`(require-params ~param)
param)
;; `req` is an alias for `required`
(defannotation req [param]
`(require-params ~param)
param)
;;; ### defendpoint
......
......@@ -205,13 +205,6 @@
(map (fn [annotation]
[(keyword annotation) (symbol arg)]))))))
(defn args-form->arg+annotations-pairs
[annotated-args-form]
{:pre [(vector? annotated-args-form)]}
(->> annotated-args-form
args-form->symbols
(mapcat symb->arg+annotations)))
;;; ### let-annotated-args
......
......@@ -21,12 +21,13 @@
(hydrate [:org_perms :organization])))
(defendpoint GET "/:id" [id fish.required]
(defendpoint GET "/:id" [id]
;; user must be getting their own details OR they must be a superuser to proceed
(check-403 (or (= id *current-user-id*) (:is_superuser @*current-user*)))
(check-404 (sel :one User :id id)))
(defannotation email [email]
`(require-params ~email)
`(check (is-email? ~email) [400 (format ~(str (name email) " '%s' is not a valid email.") ~email)])
email)
......@@ -40,11 +41,11 @@
(mapply upd User id)))
(sel :one User :id id))
(defannotation complex-password [password]
(defannotation complex-pw [password]
`(check (password/is-complex? ~password) [400 "Insufficient password strength"])
password)
(defendpoint PUT "/:id/password" [id :as {{:keys [password.required.complex-password old_password.required]} :body}]
(defendpoint PUT "/:id/password" [id :as {{:keys [password.req.complex-pw old_password.req]} :body}]
(require-params password old_password)
(check-403 (or (= id *current-user-id*)
(:is_superuser @*current-user*)))
......@@ -53,5 +54,4 @@
(set-user-password id password)
(sel :one User :id id))
(define-routes)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment