From 53a2c4d4a18c2f5903961bce7bc61cf19336157f Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Thu, 2 May 2013 19:45:39 -0400 Subject: Forum: Make anonymity typesafe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ‘username’ and ‘usernameOrAnonymous’ are now separate types. --- forum/author.urs | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) (limited to 'forum/author.urs') diff --git a/forum/author.urs b/forum/author.urs index 619aced..1f394f0 100644 --- a/forum/author.urs +++ b/forum/author.urs @@ -1,17 +1,51 @@ -type author +(********************************** A user ***********************************) -val anonymous : author -val namedAuthor : string -> author +type usernameOrAnonymous -(********************************* Instances *********************************) +(*** Instances **) -val eq_author : eq author +val eq_usernameOrAnonymous : eq usernameOrAnonymous -val show_author : show author +val show_usernameOrAnonymous : show usernameOrAnonymous -(* 'read' producing an 'author' is guaranteed to never fail, so you can use +(* 'read' producing a 'usernameOrAnonymous' is guaranteed to never fail, so you +can use 'readError' with impunity. *) +val read_usernameOrAnonymous : read usernameOrAnonymous + +val sql_usernameOrAnonymous : sql_injectable usernameOrAnonymous + + +(*** Getting the username ***) + +(* Grabs username out of MIT certificate. *) +val current : transaction usernameOrAnonymous + + +(******************************* A named user ********************************) + +type username + + +(*** Instances **) + +val eq_username : eq username + +val show_username : show username + +(* 'read' producing a 'username' is guaranteed to never fail, so you can use 'readError' with impunity. *) -val read_author : read author +val read_username : read username + +val sql_username : sql_injectable username + + +(******************************** Converting *********************************) + +val name : usernameOrAnonymous -> option username + +val orAnonymous : username -> usernameOrAnonymous -val sql_author : sql_injectable author +(* Converts a 'usernameOrAnonymous' to an 'option' tag. If anonymous, produces +empty XML. *) +val toOptionTag : use ::: {Type} -> usernameOrAnonymous -> xml select use [] -- cgit v1.2.3