From 5d89c729aed9df6dd96e3880a91897ae5dfabbca Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sun, 12 Jul 2020 22:47:03 -0700 Subject: hero: put app routes behind auth --- Hero/Client.hs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'Hero/Client.hs') 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 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 } -- cgit v1.2.3