Skip to content

Instantly share code, notes, and snippets.

@mightybyte
Forked from adinapoli/first.hs
Created October 1, 2012 14:11
Show Gist options
  • Save mightybyte/3812019 to your computer and use it in GitHub Desktop.
Save mightybyte/3812019 to your computer and use it in GitHub Desktop.
First attempt
loginUser
:: ByteString
-- ^ Username field
-> ByteString
-- ^ Password field
-> Maybe ByteString
-- ^ Remember field; Nothing if you want no remember function.
-> (AuthFailure -> Handler b (AuthManager b) ())
-- ^ Upon failure
-> Handler b (AuthManager b) ()
-- ^ Upon success
-> Handler b (AuthManager b) ()
loginUser unf pwdf remf loginFail loginSucc =
runEitherT (loginUser' unf pwdf remf)
>>= either loginFail (const loginSucc)
loginUser' :: ByteString
-> ByteString
-> Maybe ByteString
-> EitherT AuthFailure (Handler b (AuthManager b)) AuthUser
loginUser' unf pwdf remf = do
mbUsername <- lift $ getParam unf
mbPassword <- lift $ getParam pwdf
remember <- lift $ liftM (fromMaybe False)
(runMaybeT $
do field <- MaybeT $ return remf
value <- MaybeT $ getParam field
return $ value == "1")
password <- maybe (left PasswordMissing) return mbPassword
username <- maybe (left UsernameMissing) return mbUsername
-- Lifting already get the "success" value for me,
-- and store it inside loginStatus
loginStatus <- lift $ loginByUsername username (ClearText password) remember
EitherT $ return loginStatus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment