Created
March 24, 2015 16:12
-
-
Save cschneid/544dc7b166edfa81cb11 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Login where | |
import qualified Data.Text as T | |
type LoginMessage = T.Text | |
data LoginState = | |
-- This user is logged in | |
LoggedIn User | |
-- The user is not logged in. Show a form and let them do stuff | |
-- The message allows for failed logins to display something | |
| LoggedOut (Maybe LoginMessage) | |
-- We have submitted this user, and are waiting for a response | |
-- from the server | |
| LogginInProcess | |
deriving (Show) | |
data LoginAction = | |
LogOutA | |
| SubmitFormA User | |
| ResponseFailureA LoginMessage | |
| ResponseSuccessA User | |
deriving (Show) | |
loginTransition :: LoginState -> LoginAction -> LoginState | |
loginTransition LoggedIn LoginLogoutA = LoggedOut Nothing | |
loginTransition LoggedOut (SubmitFormA u) = LoginInProgress u | |
loginTransition LoginInProgress (ResponseFailureA m) = LoggedOut m | |
loginTransition LoginInProgress (ResponseSuccessA u) = LoggedIn u | |
loginTransition state action = | |
error $ "Invalid transition. From " ++ show state ++ " with " ++ show action |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment