Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn signup-handler
- [req]
- (case (req :method)
- "GET"
- (do
- @{:status 200
- :headers (default-headers)
- :body (templates/render-signup (get-in req [:flash :signup] @{}))})
- "POST"
- (do
- (def formdata (or (httpkit/parse-www-form-urlencoded (req :body))
- @{}))
- (def email (get formdata "email"))
- (def form-errors @{})
- (label _
- (when (or (nil? email) (empty? email))
- (put form-errors :email "email is required")
- (return _))
- (def activation-code (account/begin-signup email))
- (unless activation-code
- (put form-errors :email "account already exists")
- (return _))
- (mailer/send-signup-email email activation-code))
- (if (empty? form-errors)
- @{:status 200
- :headers (default-headers)
- :body (templates/render-action-result {:result "signup email sent" :next "/signup"})}
- (do
- (put (dyn :session) :flash {:signup { :form-errors form-errors }})
- @{:status 303
- :headers (merge-into (default-headers) {"Location" (req :path)})})))
- (bad-request)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement