var noMsg = ""; sig login_widget : (String, Handler((username:String, pass:String))) ~> Page fun login_widget(msg, return) { page
{stringToXml(msg)}
Start over } sig validAuth : (String, String) -> Bool fun validAuth(name, pass) { name == "foo" && pass == "bar" } sig get_user : (String) ~> String fun get_user(msg) { var current_user = getCookie("loginname"); if (current_user <> "") # User is logged in! Return creds. current_user else { # User is not logged in, show login page. var (username=name, pass=pass) = sendSuspend(fun (r){login_widget(msg, r)}); if (validAuth(name, pass)) { # User logged in successfully, set cookie and return creds. setCookie("loginname", name); name } else # User failed to log in, show page again. get_user("The password you entered was incorrect") } } sig logout : () ~> () fun logout() { setCookie("loginname", ""); } sig logoutLink : (() ~> Page) ~> Xml fun logoutLink(target) { Logout } fun main() { var user = get_user(noMsg); page
Thanks for logging in, {stringToXml(user)}.
{logoutLink(main)}
} main()