diff --git a/Yesod/Helpers/Auth/HashDB.hs b/Yesod/Helpers/Auth/HashDB.hs index 458738c6..b069e1c7 100644 --- a/Yesod/Helpers/Auth/HashDB.hs +++ b/Yesod/Helpers/Auth/HashDB.hs @@ -72,6 +72,7 @@ import Text.Hamlet (hamlet) import Control.Applicative ((<$>), (<*>)) import Data.ByteString.Lazy.Char8 (pack) import Data.Digest.Pure.SHA (sha1, showDigest) +import Data.Maybe (fromMaybe) import Database.Persist.TH (share2) import Database.Persist.GenericSql (mkMigrate) @@ -114,14 +115,17 @@ postLoginR :: (YesodAuth y, PersistBackend (YesodDB y (GGHandler Auth y IO))) => GHandler Auth y () postLoginR = do - (user, password) <- runFormPost' $ (,) - <$> stringInput "username" - <*> stringInput "password" + (mu,mp) <- runFormPost' $ (,) + <$> maybeStringInput "username" + <*> maybeStringInput "password" - isValid <- validateUser (user,password) + isValid <- case (mu,mp) of + (Nothing, _ ) -> return False + (_ , Nothing) -> return False + (Just u , Just p ) -> validateUser (u,p) if isValid - then setCreds True $ Creds "hashdb" user [] + then setCreds True $ Creds "hashdb" (fromMaybe "" mu) [] else do setMessage #if GHC7 @@ -129,7 +133,7 @@ postLoginR = do #else [$hamlet| #endif - invalid username/password + Invalid username/password |] toMaster <- getRouteToMaster redirect RedirectTemporary $ toMaster LoginR @@ -160,7 +164,7 @@ getAuthIdHashDB authR creds = do #else [$hamlet| #endif - user not found + User not found |] redirect RedirectTemporary $ authR LoginR @@ -178,28 +182,28 @@ authHashDB = AuthPlugin "hashdb" dispatch $ \tm -> #endif