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