Last active
September 8, 2015 12:23
-
-
Save agocorona/e11fe3c722b873a75f7e to your computer and use it in GitHub Desktop.
login widget. present login/pass button
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
-- normally to be used with autoRefresh and pageFlow when used with other widgets. | |
authenticateWidget :: View Html IO () | |
authenticateWidget= wform $ do | |
username <- getCurrentUser | |
if username /= anonymous | |
then do | |
private; noCache;noStore | |
return username -- if it is logged alredy, return username to the first wcallback | |
else do -- if not it tries to get the user/pass from the paramenters and log in if the user sent login/passw | |
(name, pass) <- (,) <$> (getString Nothing <! hint "login name" | |
<! size' (9 :: Int) | |
<++ br) | |
<*> (getPassword <! hint "password" | |
<! size' 9) | |
<++ br | |
<** submitButton "login" | |
val <- userValidate (name,pass) | |
case val of | |
Just msg -> notValid msg | |
Nothing -> login name >> clearEnv >> (return name) | |
-- if one of the two return the user, then wcallback erase the login/password boxes and present logged as .... logout | |
`wcallback` (\name -> ftag "b" (fromStr $ "logged as " ++ name++ " ") | |
++> pageFlow "logout" (submitButton "logout")) -- wlink ("logout" :: String) (ftag "b" $ fromStr " logout")) | |
-- the second callback is activated when logout is pressed, and call wlogin to present the login/pass boxes again | |
`wcallback` const (logout >> clearEnv >> authenticateWidget) | |
focus = [("onload","this.focus()")] | |
hint s= [("placeholder",s)] | |
size' n= [("size",show n)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment