summaryrefslogtreecommitdiff
path: root/Hero/Client.hs
diff options
context:
space:
mode:
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
}