summaryrefslogtreecommitdiff
path: root/forum/author.ur
blob: 5cbc136d14ffe66cf599eed75b9dec8f2306ffdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(********************************** A user ***********************************)

type usernameOrAnonymous = option string


(*** Instances ***)

val eq_usernameOrAnonymous = Option.eq

val show_usernameOrAnonymous =
    mkShow (
        fn nameOpt =>
           case nameOpt of
               None => "Anonymous"
             | Some nam => nam)

val read_author =
    let fun parse text =
           case text of
               "Anonymous" => None
             | nam => Some nam
    in
       mkRead parse (compose Some parse)
    end

val sql_usernameOrAnonymous = sql_option_prim


(*** Getting the username ***)

val current =
    addressOpt <- getenv (blessEnvVar "SSL_CLIENT_S_DN_Email");
    (* SSL_CLIENT_EMAIL contains the user's entire e-mail address, including
    the "@MIT.EDU" part.  Get rid of the domain name. *)
    return (address <- addressOpt;
    	    usernameAndDomain <- String.split address #"@";
    	    return usernameAndDomain.1)


(******************************* A named user ********************************)

type username = string


(*** Instances ***)

val eq_username = eq_string

val show_username = show_string

val read_username = read_string

val sql_username = sql_prim


(******************************** Converting *********************************)

fun name uOrA = uOrA

val nameError = MyOption.getError

val orAnonymous = Some

(* I can't express this in terms of whenIdentified'--I get a "substitution in
constructor is blocked by a too-deep unification variable." *)
fun whenIdentified [ctx] [use] uOrA text =
    case uOrA of
	None => <xml/>
      | Some u => text

fun whenIdentified' [ctx] [use] uOrA generator =
    case uOrA of
	None => <xml/>
      | Some u => generator u

fun toOptionTag [_use] uOrA =
    case uOrA of
	None => <xml/>
      | Some u => <xml><option>{[u]}</option></xml>