Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cms/systems/bread/alpha/cms/main.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
[systems.bread.alpha.plugin.rum :as rum]
[systems.bread.alpha.plugin.signup :as signup]
[systems.bread.alpha.plugin.account :as account]
[systems.bread.alpha.plugin.invitations :as invitations]
[systems.bread.alpha.tools.util])
(:import
[java.io Console]
Expand Down Expand Up @@ -93,6 +94,10 @@
{:name :email
:dispatcher/type ::email/settings=>
:dispatcher/component #'rise/EmailPage}]
["/invitations"
{:name :invitations
:dispatcher/type ::invitations/invitations=>
:dispatcher/component #'rise/InvitationsPage}]
["/edit"
{:name :edit
:dispatcher/type ::marx/edit=>}]
Expand Down Expand Up @@ -370,6 +375,7 @@
[(auth/plugin (:auth app-config))
(signup/plugin (:signup app-config))
(account/plugin (:account app-config))
(invitations/plugin (:invitation app-config))
(marx/plugin (:marx app-config))
(navigation/plugin (:navigation app-config))
(rum/plugin (:renderer app-config))
Expand Down
92 changes: 90 additions & 2 deletions cms/themes/rise/systems/bread/alpha/cms/theme/rise.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[systems.bread.alpha.i18n :as i18n]
[systems.bread.alpha.plugin.account :as account]
[systems.bread.alpha.plugin.email :as email]
[systems.bread.alpha.plugin.auth :as auth]))
[systems.bread.alpha.plugin.auth :as auth]
[systems.bread.alpha.plugin.invitations :as invitations]))

(defn- IntroSection [_]
{:id :intro
Expand Down Expand Up @@ -337,7 +338,7 @@
(:email/email i18n)])

(defmethod Section ::email/heading [{:keys [i18n]} _]
[:h3 (:email/email-heading i18n)])
[:h2 (:email/email-heading i18n)])

(defn- compare-emails [a b]
(cond
Expand Down Expand Up @@ -432,6 +433,93 @@
[:main
(map (partial Section data) (:email/html.email.sections config))]})

(defmethod Section ::invitations/invitations-link
[{:keys [config i18n]} _]
[:a {:href (:invitations/invitations-uri config)}
(:invitations/invitations i18n "Invitations")])

(defmethod Section ::invitations/invitations-heading [{:keys [i18n]} _]
[:h2 (:invitations/invitations i18n "Invitations")])

(defmethod Section ::invitations/invite-form
[{:keys [config i18n ring/params ring/anti-forgery-token-field user]} _]
[:form.flex.col {:method :post :action (:invitations/invitations-uri config)}
(anti-forgery-token-field)
(let [max-total (:invitations/max-total config)
left (when max-total (- max-total (count (:invitation/_invited-by user))))
any-left? (or (not max-total) (not (zero? left)))]
[:<>
(when any-left?
[:h3 (:invitations/invite i18n)])
(when max-total
[:.instruct (if any-left?
(i18n/t i18n [:invitations/total-left left])
(:invitations/total-reached i18n))])
(when (or (not max-total) (not (zero? left)))
[:.field
[:label {:for :email} (:email/email i18n)]
[:input {:id :email :name :email :type :email :value (:email params)}]
(Submit (:invitations/invite i18n "Invite") :name :action :value "send")])])])

(defn- compare-invitations [a b]
(let [redeemer-a (:invitation/redeemer a)
redeemer-b (:invitation/redeemer b)]
(cond
;; Always list pending first (reverse chronological)...
(and redeemer-a (not redeemer-b)) 1
(and redeemer-b (not redeemer-a)) -1
(and (not redeemer-a) (not redeemer-b))
(compare (:thing/updated-at b) (:thing/updated-at a))
;; ...and then redeemed.
:else (compare (:email/created-at a) (:email/created-at b)))))

(defmethod Section ::invitations/invitations-list
[{:keys [config i18n user ring/anti-forgery-token-field]} _]
(let [invitations (sort compare-invitations (:invitation/_invited-by user))]
[:.flex.col
[:h3 (:invitations/your-invitations i18n)]
(if (seq invitations)
(map (fn SentInvitation [{{:email/keys [address]} :invitation/email
:keys [db/id
invitation/code
invitation/redeemer
thing/updated-at]}]
(if redeemer
[:.flex.row
[:label address]
[:small (i18n/t i18n [:invitations/accepted-at updated-at])]]
[:form {:method :post :action (:invitations/invitations-uri config)}
(anti-forgery-token-field)
[:.field.flex.row {:data-code code}
[:input {:type :hidden :name :id :value id}]
[:.flex.col.tight
[:label address]
[:small (i18n/t i18n [:invitations/sent-at updated-at])]]
[:span.spacer]
[:button {:type :submit :name :action :value :resend}
(:invitations/resend i18n)]
[:button {:type :submit :name :action :value :revoke}
(:invitations/revoke i18n)]]]))
invitations)
[:p.instruct (:invitations/no-invitations-body i18n)])]))

(defc InvitationsPage
[{:as data :keys [i18n ring/anti-forgery-token-field]}]
{:extends SettingsPage
:key :user
:query '[:db/id
:user/username
{:invitation/_invited-by [* :thing/created-at
{:invitation/email [*]}]}]}
{:title (:invitations/invitations i18n)
:content
[:main.flex.col
;; TODO
(map (partial Section data) [::invitations/invitations-heading
:flash
::invitations/invite-form
::invitations/invitations-list])]})

(defc LogoutForm [{:keys [config i18n ring/anti-forgery-token-field]}]
{:doc "Standard logout form for the account page."}
[:form.logout-form {:method :post :action (:auth/login-uri config)}
Expand Down
5 changes: 4 additions & 1 deletion dev/main.edn
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
:store #include #join ["db-store." #or [#env STORE_BACKEND "jdbc"] ".edn"]}
:db/initial-txns
[{:invitation/code "a7d190e5-d7f4-4b92-a751-3c36add92610"
:invitation/invited-by "user.admin"}
:invitation/invited-by "user.admin"
:invitation/email {:email/address "test@localhost"}
:thing/created-at #seconds-ago 3600
:thing/updated-at #seconds-ago 0}
{:db/id "user.admin"
:user/username "bread"
:user/name "Bread User"
Expand Down
4 changes: 2 additions & 2 deletions plugins/auth/auth.i18n.edn
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
:password "Password"
:password-confirmation "Password confirmation"
:passwords-must-match "Password and confirmation must match."
:password-must-be-at-least "Password must be at least %d characters."
:password-must-be-at-most "Password must be at most %d characters."
:password-must-be-at-least "Password must be at least %d characters long."
:password-must-be-at-most "Password must be at most %d characters long."
:password-required "Password is required."
:please-scan-qr-code"Please scan the QR code to finish setting up multi-factor authentication."
:qr-code "QR code"
Expand Down
24 changes: 24 additions & 0 deletions plugins/auth/invitations.i18n.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
:en
#:invitations{
:accepted-at "Accepted %s"
:invitation-email-body "%s invited you to %s! Go here to accept:\n\n%s"
:invitation-email-subject "You've been invited to %s"
:invitation-invalid "This invitation is invalid or has already been redeemed."
:invitation-pending "Invitation pending"
:invitation-resent "Invitation resent."
:invitation-revoked "Invitation revoked."
:invitation-sent "Invitation sent."
:invitations "Invitations"
:invite "Invite"
:no-invitations-body "You haven't sent any invitations yet."
:resend "Resend"
:revoke "Revoke"
:sending-too-many "You are sending too many invitations. Please wait."
:sent-at "Sent %s"
:signup "Signup"
:total-left "You have %s invitation(s) left."
:total-reached "You have no invitations left."
:your-invitations "Your invitations"
}
}
4 changes: 2 additions & 2 deletions plugins/auth/signup.i18n.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
:en
#:signup{
:all-fields-required "All fields are required."
:create-account "Create account"
:email-exists "Email already exists."
:error "Account locked"
:invitation-invalid "This invitation is invalid or has already been redeemed."
:please-choose-username-password "Please choose a username and password."
:signup "Signup"
:site-invite-only "This site is invite-only."
:create-account "Create account"
}
}
3 changes: 3 additions & 0 deletions plugins/auth/systems/bread/alpha/plugin/account.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
[systems.bread.alpha.i18n :as i18n]
[systems.bread.alpha.ring :as ring]
[systems.bread.alpha.plugin.auth :as auth]
[systems.bread.alpha.plugin.signup :as signup]
[systems.bread.alpha.plugin.invitations :as invitations]
[systems.bread.alpha.plugin.email :as email])
(:import
[java.text SimpleDateFormat]))
Expand Down Expand Up @@ -257,6 +259,7 @@
"America/New_York"]
html-account-header [::account-link
::email/settings-link
::invitations/invitations-link
:spacer
::logout-form]
html-account-form [::heading
Expand Down
Loading
Loading