aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoris2015-12-30 00:43:01 +0100
committerJoris2015-12-30 00:43:01 +0100
commitae3fd8922969f37292007c6e9f9cb5b1a11e4acd (patch)
tree67ccd96b9b13d3acbe6d6f17606fa2b84262d9a2 /src
parente32a9126ae7fd7f9596dd08b64ecab8644d994bd (diff)
Prevent from exception when calling persona assertion url
Diffstat (limited to 'src')
-rw-r--r--src/server/Persona.hs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/server/Persona.hs b/src/server/Persona.hs
index 8055e8b..267ee3b 100644
--- a/src/server/Persona.hs
+++ b/src/server/Persona.hs
@@ -7,6 +7,7 @@ module Persona
import Control.Monad (guard)
import Network.HTTP.Conduit
+import Network.HTTP.Types.Status (ok200)
import Data.Text (Text)
import qualified Data.Text as T
@@ -23,7 +24,7 @@ verifyEmail config assertion = do
initReq <- parseUrl "https://verifier.login.persona.org/verify"
let request =
- (flip urlEncodedBody) initReq $
+ (flip urlEncodedBody) (initReq { checkStatus = \_ _ _ -> Nothing }) $
[ ("assertion", encodeUtf8 $ assertion)
, ("audience", encodeUtf8 $ hostname config)
]
@@ -31,7 +32,9 @@ verifyEmail config assertion = do
manager <- newManager tlsManagerSettings
response <- httpLbs request manager
- return . parseEmail . decodeUtf8 . toStrict . responseBody $ response
+ if responseStatus response == ok200
+ then return . parseEmail . decodeUtf8 . toStrict . responseBody $ response
+ else return Nothing
parseEmail :: Text -> Maybe Text
parseEmail payload = do