# HG changeset patch # User Karn Kallio # Date 1303330527 16200 # Node ID a5574ec3991fdd53651fa4c4649effbefe0c24d6 # Parent c0731afcb0c707e7f697c74f8a1988052c2ae93e Generalize the formatting options a bit. diff -r c0731afcb0c7 -r a5574ec3991f src/ur/openidUser.ur --- a/src/ur/openidUser.ur Mon Apr 18 01:49:24 2011 -0430 +++ b/src/ur/openidUser.ur Wed Apr 20 15:45:27 2011 -0430 @@ -7,6 +7,30 @@ datatype choose_result a = Success of a | Failure of string +signature CTLDISPLAY = sig + val formatUser : xbody -> xbody + val formatLogout : url -> xbody + val formatSignup : url -> xbody + val formatLogon : ({User : string} -> transaction page) -> xbody +end + +structure DefaultDisplay : CTLDISPLAY = struct + fun formatUser user = + You are logged in as {user} + + fun formatLogout url = + Log Out + + fun formatSignup url = + Sign Up + + fun formatLogon handler = + +
+
+end + + functor Make(M: sig con cols :: {Type} constraint [Id] ~ cols @@ -29,8 +53,7 @@ val formClass : css_class val fakeId : option string - val ctlDisplay : {User : {Status : xbody, Other : xbody}, - Guest : {Status : xbody, Other : xbody}} + structure CtlDisplay : CTLDISPLAY end) = struct type user = string @@ -298,11 +321,14 @@ in cur <- current; here <- currentUrl; + case cur of - Some cur => return {Status = {M.ctlDisplay.User.Status}{[cur]}, - Other = {M.ctlDisplay.User.Other}} - | None => return {Status = {M.ctlDisplay.Guest.Status}
, - Other = {M.ctlDisplay.Guest.Other}} + Some cur => return {Status = (M.CtlDisplay.formatUser {[cur]}), + Other = {Url = (url (logout ())), + Xml = (M.CtlDisplay.formatLogout (url (logout ())))}} + | None => return {Status = (M.CtlDisplay.formatLogon (logon (show here))), + Other = {Url = (url (signup (show here))), + Xml = (M.CtlDisplay.formatSignup (url (signup (show here))))}} end task periodic 60 = fn () => dml (DELETE FROM session diff -r c0731afcb0c7 -r a5574ec3991f src/ur/openidUser.urs --- a/src/ur/openidUser.urs Mon Apr 18 01:49:24 2011 -0430 +++ b/src/ur/openidUser.urs Wed Apr 20 15:45:27 2011 -0430 @@ -9,6 +9,26 @@ datatype choose_result a = Success of a | Failure of string +(* Formatting options for the gui elements and controls. *) +signature CTLDISPLAY = sig + + val formatUser : xbody -> xbody + (* Format the display of the logged on user *) + + val formatLogout : url -> xbody + (* Format the logout link *) + + val formatSignup : url -> xbody + (* Format the signup link *) + + val formatLogon : ({User : string} -> transaction page) -> xbody + (* Format the login form *) +end + +(* Some reasonable default gui control formats for programmers in a hurry. *) +structure DefaultDisplay : CTLDISPLAY + + (* Instantiate this functor to create your customized authentication scheme. *) functor Make(M: sig con cols :: {Type} @@ -66,10 +86,9 @@ (* If set, this string is always accepted as a verified * identifier, which can be useful during development (say, * when you're off-network). *) - - val ctlDisplay : {User : {Status : xbody, Other : xbody}, - Guest : {Status : xbody, Other : xbody}} - (* These help formatting the user status controls *) + + structure CtlDisplay : CTLDISPLAY + (* Tells how to format the GUI elements. *) end) : sig type user @@ -86,14 +105,16 @@ val current : transaction (option user) (* Figure out which, if any, user is logged in on this connection. *) + val main : (string -> xbody -> transaction page) -> transaction {Status : xbody, - Other : xbody} + Other : {Url : url, Xml : xbody}} + (* Pass in your generic page template; get out the HTML snippet for user * management, suitable for, e.g., inclusion in your standard page * header. The output gives a "status" chunk, which will either be a login * form or a message about which user is logged in; and an "other" chunk, * which will be a log out or sign up link. *) - + end (* Functor outputs will contain buttons specialized to particular well-known