score-the-pigs/src/com/biffweb/my_project/home.clj

121 lines
4 KiB
Clojure

(ns com.biffweb.my-project.home
(:require
[com.biffweb :as biff]
[com.biffweb.my-project.middleware :as mid]
[com.biffweb.my-project.ui :as ui]
[com.biffweb.my-project.settings :as settings]))
(defn home-page [{:keys [params] :as ctx}]
(ui/page
ctx
[:article
(biff/form
{:action "/auth/send-link"
:id "signup"
:hidden {:on-error "/"}}
[:h2 (str "Sign up for " settings/app-name)]
[:fieldset {:role "group"}
[:input#email {:name "email"
:type "email"
:autocomplete "email"
:placeholder "Enter your email address"}]
[:input
{:type "submit"
:value "Sign up"}]]
(when-some [error (:error params)]
[:<>
[:p.pico-color-red-500
(case error
"invalid-email" "Invalid email. Try again with a different address."
"send-failed" (str "We weren't able to send an email to that address. "
"If the problem persists, try another address.")
"There was an error.")]])
[:small "Already have an account? " [:a.link {:href "/signin"} "Sign in"] "."])]))
(defn link-sent [{:keys [params] :as ctx}]
(ui/page
ctx
[:h2 "Check your inbox"]
[:p "We've sent a sign-in link to " [:span.font-bold (:email params)] "."]))
(defn verify-email-page [{:keys [params] :as ctx}]
(ui/page
ctx
[:article
[:h2 (str "Sign up for " settings/app-name)]
(biff/form
{:action "/auth/verify-link"
:hidden {:token (:token params)}}
[:div [:label {:for "email"}
"It looks like you opened this link on a different device or browser than the one "
"you signed up on. For verification, please enter the email you signed up with:"]]
[:fieldset {:role "group"}
[:input#email {:name "email"
:type "email"
:autocomplete "email"
:placeholder "Enter your email address"}]
[:input
{:type "submit"
:value "Sign in"}]])
(when-some [error (:error params)]
[:small.pico-color-red-500
(case error
"incorrect-email" "Incorrect email address. Try again."
"There was an error.")])]))
(defn signin-page [{:keys [params] :as ctx}]
(ui/page
ctx
[:article
(biff/form
{:action "/auth/send-code"
:id "signin"
:hidden {:on-error "/signin"}}
[:h2 "Sign in to " settings/app-name]
[:fieldset {:role "group"}
[:input#email {:name "email"
:type "email"
:autocomplete "email"
:placeholder "Enter your email address"}]
[:input
{:type "submit"
:value "Sign in"}]]
(when-some [error (:error params)]
[:div
[:small.pico-color-red-500
(case error
"invalid-email" "Invalid email. Try again with a different address."
"send-failed" (str "We weren't able to send an email to that address. "
"If the problem persists, try another address.")
"invalid-link" "Invalid or expired link. Sign in to get a new link."
"not-signed-in" "You must be signed in to view that page."
"There was an error.")]])
[:small "Don't have an account yet? " [:a.link {:href "/"} "Sign up"] "."])]))
(defn enter-code-page [{:keys [params] :as ctx}]
(ui/page
ctx
[:article
(biff/form
{:action "/auth/verify-code"
:id "code-form"
:hidden {:email (:email params)}}
[:div [:label {:for "code"} "Enter the 6-digit code that we sent to "
[:span.font-bold (:email params)]]]
[:input#code {:name "code" :type "text"}]
(when-some [error (:error params)]
[:small.pico-color-red-500
(case error
"invalid-code" "Invalid code."
"There was an error.")]))
(biff/form
{:action "/auth/send-code"
:id "signin"
:hidden {:email (:email params)
:on-error "/signin"}})]))
(def module
{:routes [[]]})