diff options
| author | LLLL Colonq <llll@colonq> | 2024-12-10 14:28:30 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2024-12-10 14:28:30 -0500 |
| commit | 638bdddeb10b18dd35af5a6de2950aaa3c8a5e44 (patch) | |
| tree | 4a995c6b740ef3ef2b5619c7e9ffb68a970ae156 /src/Main/Auth.purs | |
| parent | ff56e27d4874f559a62bea5e6eeb258443e31936 (diff) | |
Initial mrgreen activities
Diffstat (limited to 'src/Main/Auth.purs')
| -rw-r--r-- | src/Main/Auth.purs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Main/Auth.purs b/src/Main/Auth.purs new file mode 100644 index 0000000..04fe6e1 --- /dev/null +++ b/src/Main/Auth.purs @@ -0,0 +1,46 @@ +module Main.Auth where + +import Prelude + +import Auth (getQueryRedirect, getResponseRedirect) +import Data.HTTP.Method (Method(..)) +import Data.Maybe (Maybe(..)) +import Effect (Effect) +import Effect.Aff (launchAff_) +import Effect.Class (liftEffect) +import Effect.Console (log) +import Fetch (fetch) +import UI as UI +import Utils (byId, getValue, listen, removeClass) +import Web.Event.Event as Ev + +main :: Effect Unit +main = launchAff_ do + liftEffect $ log "hello from auth" + container <- byId "lcolonq-auth-login" + removeClass "lcolonq-invisible" container + form <- byId "lcolonq-auth-form" + listen form "submit" \ev -> launchAff_ do + liftEffect $ Ev.preventDefault ev + usernameInp <- byId "lcolonq-auth-username" + passwordInp <- byId "lcolonq-auth-password" + username <- getValue usernameInp + password <- getValue passwordInp + rd <- getQueryRedirect + { json: resp } <- fetch "/api/firstfactor" + { method: POST + , headers: { "Content-Type": "application/json" } + , body: UI.toJSON + { username + , password + , targetURL: case rd of + Just r -> r + Nothing -> "https://secure.colonq.computer" + } + } + res <- resp + getResponseRedirect res >>= case _ of + Nothing -> do + err <- byId "lcolonq-auth-error" + removeClass "lcolonq-invisible" err + Just r -> UI.redirect r |
