Do parseJsonBody only when form data is not found

This commit is contained in:
Sibi Prabakaran 2016-12-07 14:08:37 +05:30
parent 0255f93c22
commit 8f8c99db88
No known key found for this signature in database
GPG Key ID: D19E3E0EBB557613

View File

@ -399,13 +399,14 @@ registerHelper allowUsername dest = do
y <- lift getYesod
checkCsrfHeaderOrParam defaultCsrfHeaderName defaultCsrfParamName
pidentifier <- lookupPostParam "email"
(jidentifier :: Result Value) <- lift parseJsonBody
let midentifier = case pidentifier of
Nothing -> case jidentifier of
Error _ -> Nothing
Success val -> parseMaybe parseEmail val
Just _ -> pidentifier
midentifier <- case pidentifier of
Nothing -> do
(jidentifier :: Result Value) <- lift parseJsonBody
case jidentifier of
Error _ -> return Nothing
Success val -> return $ parseMaybe parseEmail val
Just _ -> return pidentifier
let eidentifier = case midentifier of
Nothing -> Left Msg.NoIdentifierProvided
Just x
@ -531,12 +532,14 @@ postLoginR = do
result <- lift $ runInputPostResult $ (,)
<$> ireq textField "email"
<*> ireq textField "password"
(creds :: Result Value) <- lift parseJsonBody
let midentifier = case result of
FormSuccess (iden, pass) -> Just (iden, pass)
_ -> case creds of
Error _ -> Nothing
Success val -> parseMaybe parseCreds val
midentifier <- case result of
FormSuccess (iden, pass) -> return $ Just (iden, pass)
_ -> do
(creds :: Result Value) <- lift parseJsonBody
case creds of
Error _ -> return Nothing
Success val -> return $ parseMaybe parseCreds val
case midentifier of
Nothing -> loginErrorMessageI LoginR Msg.NoIdentifierProvided