Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. (defn signup-handler
  2. [req]
  3. (case (req :method)
  4. "GET"
  5. (do
  6. @{:status 200
  7. :headers (default-headers)
  8. :body (templates/render-signup (get-in req [:flash :signup] @{}))})
  9. "POST"
  10. (do
  11. (def formdata (or (httpkit/parse-www-form-urlencoded (req :body))
  12. @{}))
  13. (def email (get formdata "email"))
  14. (def form-errors @{})
  15.  
  16. (label _
  17. (when (or (nil? email) (empty? email))
  18. (put form-errors :email "email is required")
  19. (return _))
  20.  
  21. (def activation-code (account/begin-signup email))
  22. (unless activation-code
  23. (put form-errors :email "account already exists")
  24. (return _))
  25.  
  26. (mailer/send-signup-email email activation-code))
  27.  
  28. (if (empty? form-errors)
  29. @{:status 200
  30. :headers (default-headers)
  31. :body (templates/render-action-result {:result "signup email sent" :next "/signup"})}
  32. (do
  33. (put (dyn :session) :flash {:signup { :form-errors form-errors }})
  34. @{:status 303
  35. :headers (merge-into (default-headers) {"Location" (req :path)})})))
  36. (bad-request)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement