New member applications
[hcoop/zz_old/portal.git] / app.sml
1 structure App :> APP =
2 struct
3
4 open Init Sql Util
5
6 datatype status =
7 CONFIRMING
8 | PENDING
9 | ACCEPTED
10 | REJECTED
11
12 val statusFromInt =
13 fn 0 => CONFIRMING
14 | 1 => PENDING
15 | 2 => ACCEPTED
16 | 3 => REJECTED
17 | _ => raise C.Sql "Bad status"
18
19 val statusToInt =
20 fn CONFIRMING => 0
21 | PENDING => 1
22 | ACCEPTED => 2
23 | REJECTED => 3
24
25 fun statusFromSql v = statusFromInt (C.intFromSql v)
26 fun statusToSql s = C.intToSql (statusToInt s)
27
28 type app = { id : int, name : string, rname : string, email : string,
29 forward : bool, uses : string, other : string,
30 passwd : string, status : status, stamp : C.timestamp }
31
32 fun mkAppRow [id, name, rname, email, forward, uses, other, passwd, status, stamp] =
33 { id = C.intFromSql id, name = C.stringFromSql name, rname = C.stringFromSql rname,
34 email = C.stringFromSql email, forward = C.boolFromSql forward,
35 uses = C.stringFromSql uses, other = C.stringFromSql other, passwd = C.stringFromSql passwd,
36 status = statusFromSql status, stamp = C.timestampFromSql stamp }
37 | mkAppRow r = rowError ("app", r)
38
39 fun lookupApp id =
40 case C.oneOrNoRows (getDb ()) ($`SELECT id, name, rname, email, forward, uses, other, passwd, status, stamp
41 FROM MemberApp
42 WHERE id = ^(C.intToSql id)`) of
43 SOME row => mkAppRow row
44 | NONE => raise Fail "Membership application not found"
45
46 end