-
-
Save mightybyte/3812019 to your computer and use it in GitHub Desktop.
First attempt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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