summaryrefslogtreecommitdiff
path: root/Hero/Client.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-07-12 22:47:03 -0700
committerBen Sima <ben@bsima.me>2020-07-12 22:48:39 -0700
commit5d89c729aed9df6dd96e3880a91897ae5dfabbca (patch)
tree5fcd382629553830dbc16232dc71e238084ce9ce /Hero/Client.hs
parenteae8ebdaa33fc17050703c4251e90a8a313739a3 (diff)
hero: put app routes behind auth
Diffstat (limited to 'Hero/Client.hs')
-rw-r--r--Hero/Client.hs25
1 files changed, 11 insertions, 14 deletions
diff --git a/Hero/Client.hs b/Hero/Client.hs
index 06a7eab..5429855 100644
--- a/Hero/Client.hs
+++ b/Hero/Client.hs
@@ -21,7 +21,7 @@ module Hero.Client where
import Alpha
import Biz.Auth as Auth
-import Data.Aeson (eitherDecodeStrict)
+import qualified Data.Aeson as Aeson
import qualified Data.Set as Set
import qualified GHC.Show as Legacy
import GHCJS.Types (JSVal)
@@ -31,6 +31,7 @@ import Hero.App
Comic (..),
ComicReaderState (..),
ComicReaderView (..),
+ LoginForm (..),
Model (..),
User (..),
audioId,
@@ -182,6 +183,7 @@ move ValidateUserPassword model =
[doLogin, (SetComics </ fetchComics)]
where
doLogin = do
+ jslog "starting doLogin"
user <- getValue =<< Document.getElementById "user"
pass <- getValue =<< Document.getElementById "pass"
jslog "sending login"
@@ -201,7 +203,7 @@ fetchComics = Ajax.xhrByteString req /> Ajax.contents >>= \case
Just json ->
pure $ Network.fromEither
$ either (Left . ms) pure
- $ eitherDecodeStrict json
+ $ Aeson.eitherDecodeStrict json
where
req =
Ajax.Request
@@ -226,26 +228,21 @@ sendLogin u p = Ajax.xhrByteString req /> Ajax.contents >>= \case
Just json ->
pure $ Network.fromEither
$ either (Left . ms) pure
- $ eitherDecodeStrict json
+ $ Aeson.eitherDecodeStrict json
where
req =
Ajax.Request
{ Ajax.reqMethod = Ajax.POST,
- Ajax.reqURI = "/login-hook",
- Ajax.reqLogin = Nothing, -- FIXME
+ Ajax.reqURI = "/auth",
+ Ajax.reqLogin = Nothing, -- FIXME?
Ajax.reqHeaders =
[ ("Accept", "application/json"),
("Content-Type", "application/json")
],
Ajax.reqWithCredentials = False,
- -- TODO: make this use Aeson
Ajax.reqData =
- Ajax.StringData $
- Miso.String.concat
- [ "{\"loginEmail\": \"",
- u,
- "\", \"loginPass\": \"",
- p,
- "\"}"
- ]
+ LoginForm (fromMisoString u) (fromMisoString p)
+ |> Aeson.encode
+ |> ms
+ |> Ajax.StringData
}