diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2013-04-22 13:42:45 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2013-04-22 13:42:45 -0400 |
commit | 3c4174548b561c4813ad1f4df4d59104a81885d3 (patch) | |
tree | bacfc67297c19c9167673637295de7313d0320e2 /forum | |
parent | 6c313e88105bbaf6d0bb44d8a8ea4cf600acaa83 (diff) |
Forum: Record who asked each question
Diffstat (limited to 'forum')
-rw-r--r-- | forum/forum.ur | 23 | ||||
-rw-r--r-- | forum/lib.urp | 2 |
2 files changed, 23 insertions, 2 deletions
diff --git a/forum/forum.ur b/forum/forum.ur index df53603..9556068 100644 --- a/forum/forum.ur +++ b/forum/forum.ur @@ -29,13 +29,27 @@ table question : { Id : int, } PRIMARY KEY Id sequence questionIdS +fun showAskerOpt (askerOpt : option string) : string = + case askerOpt of + None => "Anonymous" + | Some nam => nam + +fun readAskerOpt (text : string) : option string = + case text of + "Anonymous" => None + | nam => Some nam + +(* Grabs real name out of MIT certificate. *) +val getName = getenv (blessEnvVar "SSL_CLIENT_S_DN_CN") + fun prettyPrintQuestion row : xbody = <xml> - <p>{[row.Question.Title]}: {[row.Question.Body]} (asked by {[row.Question.Asker]})</p> + <p>{[row.Question.Title]}: {[row.Question.Body]} (asked by {[showAskerOpt row.Question.Asker]})</p> </xml> fun main () : transaction page = newestQuestions <- queryX (SELECT * FROM question) prettyPrintQuestion; + askerOpt <- getName; return ( Template.generic (Some "Forum") <xml> <div class={content}> @@ -45,6 +59,11 @@ fun main () : transaction page = <form> <textbox {#Title} size=80 /><br /> <textarea {#Body} rows=12 cols=80 /><br /> + Asking as: + <select {#Asker}> + <option>{[showAskerOpt askerOpt]}</option> + <option>Anonymous</option> + </select> <submit action={ask} value="Ask" /> </form> </div> @@ -54,7 +73,7 @@ fun main () : transaction page = and ask submission = id <- nextval questionIdS; dml (INSERT INTO question (Id, Title, Body, Asker) - VALUES ({[id]}, {[submission.Title]}, {[submission.Body]}, {[Some "test user"]})); + VALUES ({[id]}, {[submission.Title]}, {[submission.Body]}, {[readAskerOpt submission.Asker]})); main () end diff --git a/forum/lib.urp b/forum/lib.urp index 9e01f09..8f0ef71 100644 --- a/forum/lib.urp +++ b/forum/lib.urp @@ -1,2 +1,4 @@ +allow env SSL_CLIENT_S_DN_CN + ../styles forum |