summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.css4
-rw-r--r--src/Auth.js4
-rw-r--r--src/Auth.purs3
-rw-r--r--src/Main.purs44
-rw-r--r--src/UI.js3
-rw-r--r--src/UI.purs4
-rw-r--r--templates/auth/index.html6
7 files changed, 31 insertions, 37 deletions
diff --git a/main.css b/main.css
index 3938c31..ccef777 100644
--- a/main.css
+++ b/main.css
@@ -341,7 +341,3 @@ a.lcolonq-button-link :active {
#lcolonq-auth-submit {
display: none;
}
-
-#lcolonq-auth-logout-link {
- text-decoration: underline;
-}
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
diff --git a/src/UI.js b/src/UI.js
index 5003e21..b27b10b 100644
--- a/src/UI.js
+++ b/src/UI.js
@@ -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
diff --git a/templates/auth/index.html b/templates/auth/index.html
index 976a7a6..7b5cc03 100644
--- a/templates/auth/index.html
+++ b/templates/auth/index.html
@@ -29,11 +29,5 @@ CONFIG_SUBST
</form>
</div>
</div>
- <div id="lcolonq-auth-logout" class="lcolonq-auth lcolonq-invisible">
- <div class="lcolonq-auth-box">
- <h1>log out?</h1>
- <a id="lcolonq-auth-logout-link">yeah</a>
- </div>
- </div>
</body>
</html>