diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Auth.js | 4 | ||||
| -rw-r--r-- | src/Auth.purs | 3 | ||||
| -rw-r--r-- | src/Main.purs | 44 | ||||
| -rw-r--r-- | src/UI.js | 3 | ||||
| -rw-r--r-- | src/UI.purs | 4 |
5 files changed, 31 insertions, 27 deletions
diff --git a/src/Auth.js b/src/Auth.js index d9c21df..9d5060c 100644 --- a/src/Auth.js +++ b/src/Auth.js @@ -48,3 +48,7 @@ export const _getToken = (Just) => (Nothing) => (pair) => () => { export const _clearSessionCookie = () => { document.cookie = "authelia_session=; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=None; Secure"; }; + +export const getRedirect = (x) => { + return x.redirect; +}; diff --git a/src/Auth.purs b/src/Auth.purs index 7f87f83..a98b575 100644 --- a/src/Auth.purs +++ b/src/Auth.purs @@ -8,6 +8,7 @@ import Data.Maybe (Maybe(..)) import Data.Tuple (Tuple(..)) import Effect (Effect) import Effect.Class (class MonadEffect, liftEffect) +import Foreign (Foreign) foreign import _startTwitchAuth :: String -> String -> Effect Unit startTwitchAuth :: forall m. MonadEffect m => m Unit @@ -31,3 +32,5 @@ authHeader (Tuple t n) = foreign import _clearSessionCookie :: Effect Unit clearSessionCookie :: forall m. MonadEffect m => m Unit clearSessionCookie = liftEffect _clearSessionCookie + +foreign import getRedirect :: Foreign -> String diff --git a/src/Main.purs b/src/Main.purs index e286a24..4d0ec0d 100644 --- a/src/Main.purs +++ b/src/Main.purs @@ -3,7 +3,7 @@ module Main where import Prelude import Audio as Audio -import Auth (AuthInfo, authHeader, getToken, startTwitchAuth, clearSessionCookie) +import Auth (AuthInfo, authHeader, getToken, startTwitchAuth, clearSessionCookie, getRedirect) import Config as Config import Data.String as String import Data.Array (head) @@ -232,32 +232,22 @@ mainMenu = launchAff_ do mainAuth :: Effect Unit mainAuth = launchAff_ do liftEffect $ log "hello from auth" - { status } <- fetch "https://secure.colonq.computer/api/status" {} - case status of - 200 -> do - container <- byId "lcolonq-auth-logout" - removeClass "lcolonq-invisible" container - logout <- byId "lcolonq-auth-logout-link" - listen logout "click" \_ev -> do - clearSessionCookie - UI.reload - _ -> do - 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 - { text: resp } <- fetch "/api/firstfactor" - { method: POST - , headers: { "Content-Type": "application/json" } - , body: UI.toJSON { username, password } - } - res <- resp - liftEffect $ log res + 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 + { json: resp } <- fetch "/api/firstfactor" + { method: POST + , headers: { "Content-Type": "application/json" } + , body: UI.toJSON { username, password } + } + res <- resp + liftEffect $ log $ getRedirect res main :: Effect Unit main = case Config.mode of @@ -4,3 +4,6 @@ export const _toJSON = (x) => JSON.stringify(x); export const _reload = () => { window.location.reload(); }; +export const _redirect = (url) => () => { + window.location.href = url; +}; diff --git a/src/UI.purs b/src/UI.purs index d9a01bc..ac4d694 100644 --- a/src/UI.purs +++ b/src/UI.purs @@ -19,3 +19,7 @@ toJSON = _toJSON foreign import _reload :: Effect Unit reload :: forall m. MonadEffect m => m Unit reload = liftEffect _reload + +foreign import _redirect :: String -> Effect Unit +redirect :: forall m. MonadEffect m => String -> m Unit +redirect url = liftEffect $ _redirect url |
