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"
(jidentifier :: Result Value) <- lift parseJsonBody midentifier <- case pidentifier of
let midentifier = case pidentifier of Nothing -> do
Nothing -> case jidentifier of (jidentifier :: Result Value) <- lift parseJsonBody
Error _ -> Nothing case jidentifier of
Success val -> parseMaybe parseEmail val Error _ -> return Nothing
Just _ -> pidentifier Success val -> return $ parseMaybe parseEmail val
Just _ -> return 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"
(creds :: Result Value) <- lift parseJsonBody
let midentifier = case result of midentifier <- case result of
FormSuccess (iden, pass) -> Just (iden, pass) FormSuccess (iden, pass) -> return $ Just (iden, pass)
_ -> case creds of _ -> do
Error _ -> Nothing (creds :: Result Value) <- lift parseJsonBody
Success val -> parseMaybe parseCreds val case creds of
Error _ -> return Nothing
Success val -> return $ parseMaybe parseCreds val
case midentifier of case midentifier of
Nothing -> loginErrorMessageI LoginR Msg.NoIdentifierProvided Nothing -> loginErrorMessageI LoginR Msg.NoIdentifierProvided