-
-
Save pbzdyl/5f3cc9c724be0fd7fc7c9e32ccd6e777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns app.ui.login | |
(:require [goog.net.cookies :as cks] | |
[app.rpc :as rpc] | |
[ui.form :as form] | |
[ui.button :as button] | |
[workflow.form :as workflow] | |
[ui.modal :as modal] | |
[ui.app :as app])) | |
(def schema | |
{:network (.get goog.net.cookies "network") | |
:email nil | |
:password nil}) | |
(defn logged-in | |
[current-login] | |
(fn [form-machine] | |
(.set goog.net.cookies "network" @(:network (:data form-machine))) | |
(workflow/reset form-machine) | |
(reset! current-login schema))) | |
(defelem index | |
[attr kids] | |
((app/intercept | |
(let [current-login (cell {:network (.get goog.net.cookies "network") :email nil :password nil}) | |
forgot (cell false) | |
!forgot (cell= (not forgot)) | |
titles {true "Recover Password" false "Log In"} | |
link-text (cell= (if forgot "Cancel" "I forgot my password"))] | |
(form/with-form [{:keys [data error state exception loading] :as form-machine} | |
(workflow/form-machine | |
:current current-login | |
:action #((if @forgot rpc/forgot rpc/login) %) | |
:schema schema | |
:success (logged-in current-login))] | |
(modal/modal-dialog | |
:size :md | |
(modal/modal-header | |
(modal/modal-title | |
(span :text (cell= (titles forgot))))) | |
(form | |
:submit #(workflow/submit form-machine) | |
(modal/modal-body | |
(form/with-field :network | |
(form/validation-field | |
(label "Organization") | |
(form/text-input :focus-select !forgot) | |
(form/validation-message))) | |
(form/with-field :email | |
(form/validation-field | |
(label "Email Address") | |
(form/text-input :focus-select forgot) | |
(form/validation-message))) | |
(form/with-field :password | |
(form/validation-field | |
:toggle !forgot | |
(label "Password") | |
(form/password-input) | |
(form/validation-message)))) | |
(modal/modal-footer | |
:class "text-left" | |
(form/validation-alert) | |
(form/submit-primary "Submit") | |
(button/link | |
:click #(swap! forgot not) | |
:text (cell= (titles (not forgot)))))))))) | |
attr kids)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment