From f99787ee67f622be9965dfccd93085f412064373 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 5 Oct 2020 16:52:58 -0400 Subject: [PATCH] fix connect --- Urbit/Airlock.hs | 14 +++++++------- test.hs | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Urbit/Airlock.hs b/Urbit/Airlock.hs index b8dc617..cc30bdd 100644 --- a/Urbit/Airlock.hs +++ b/Urbit/Airlock.hs @@ -12,9 +12,10 @@ where import Control.Lens import qualified Data.Aeson as Aeson -import qualified Data.ByteString.Lazy as L import Data.ByteString (ByteString) +import qualified Data.ByteString.Lazy as L import Data.Text (Text) +import qualified Data.Text.Encoding as Encoding import Network.Wreq (FormParam ((:=))) import qualified Network.Wreq as Wreq import qualified Network.Wreq.Session as Session @@ -23,6 +24,7 @@ import qualified Network.Wreq.Session as Session data Ship = Ship { session :: Maybe Session.Session, + name :: ShipName, -- | Track the latest event we saw (needed for poking). lastEventId :: Int, -- | Internet-facing access point, like 'http://sampel-palnet.arvo.network' @@ -47,7 +49,7 @@ type Mark = Text type Subscription = Text --- | The `@p` for the ship. +-- | The `@p` for the ship (no leading ~). type ShipName = Text -- | @@ -55,12 +57,10 @@ nextEventId :: Ship -> Int nextEventId Ship {lastEventId} = lastEventId + 1 -- | Connect and login to the ship. Returns the 'urbauth' cookie. -connect :: Ship -> IO (Maybe ByteString) +connect :: Ship -> IO (Maybe Wreq.Cookie) connect ship = do - -- post to /~/login with json {"password": } - let params = Wreq.defaults & Wreq.param "password" .~ [(code ship)] - r <- Wreq.getWith params (url ship <> "/~/login") - return $ r ^? Wreq.responseHeader "Set-Cookie" + r <- Wreq.postWith Wreq.defaults (url ship <> "/~/login") ["password" := (code ship)] + return $ r ^? Wreq.responseCookie (Encoding.encodeUtf8 $ "urbauth-~" <> name ship) -- | Poke a ship. poke :: diff --git a/test.hs b/test.hs index a5830a8..0d9aba2 100644 --- a/test.hs +++ b/test.hs @@ -41,6 +41,7 @@ fakezod :: Ship fakezod = Ship { session = Nothing, + name = "zod", lastEventId = 0, url = "http://localhost:8081", code = "lidlut-tabwed-pillex-ridrup",