From 638bdddeb10b18dd35af5a6de2950aaa3c8a5e44 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Tue, 10 Dec 2024 14:28:30 -0500 Subject: Initial mrgreen activities --- src/Main/Auth.purs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Main/Auth.purs (limited to 'src/Main/Auth.purs') 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 -- cgit v1.2.3