Change granter.sh to give permissions to user specified on command line
[hcoop/zz_old/portal.git] / app.sml
diff --git a/app.sml b/app.sml
index 5b6a87f..d018983 100644 (file)
--- a/app.sml
+++ b/app.sml
@@ -28,31 +28,34 @@ val statusToInt =
 fun statusFromSql v = statusFromInt (C.intFromSql v)
 fun statusToSql s = C.intToSql (statusToInt s)
 
-type app = { id : int, name : string, rname : string, email : string,
+type app = { id : int, name : string, rname : string, gname : string option, email : string,
             forward : bool, uses : string, other : string,
-            passwd : string, status : status, applied : C.timestamp,
+            passwd : string, status : status, applied : C.timestamp, ipaddr : string option,
             confirmed : C.timestamp option, decided : C.timestamp option,
             msg : string}
 
-fun mkAppRow [id, name, rname, email, forward, uses, other, passwd, status, applied, confirmed, decided, msg] =
+fun mkAppRow [id, name, rname, gname, email, forward, uses, other, passwd, status,
+             applied, ipaddr, confirmed, decided, msg] =
     { id = C.intFromSql id, name = C.stringFromSql name, rname = C.stringFromSql rname,
+      gname = (if C.isNull gname then NONE else SOME (C.stringFromSql gname)),
       email = C.stringFromSql email, forward = C.boolFromSql forward,
       uses = C.stringFromSql uses, other = C.stringFromSql other, passwd = C.stringFromSql passwd,
       status = statusFromSql status, applied = C.timestampFromSql applied,
+      ipaddr = (if C.isNull ipaddr then NONE else SOME (C.stringFromSql ipaddr)),
       confirmed = if C.isNull confirmed then NONE else SOME (C.timestampFromSql confirmed),
       decided = if C.isNull decided then NONE else SOME (C.timestampFromSql decided),
       msg = C.stringFromSql msg}
   | mkAppRow r = rowError ("app", r)
 
 fun lookupApp id =
-    case C.oneOrNoRows (getDb ()) ($`SELECT id, name, rname, email, forward, uses, other, passwd, status, applied, confirmed, decided, msg
+    case C.oneOrNoRows (getDb ()) ($`SELECT id, name, rname, gname, email, forward, uses, other, passwd, status, applied, ipaddr, confirmed, decided, msg
                                     FROM MemberApp
                                     WHERE id = ^(C.intToSql id)`) of
        SOME row => mkAppRow row
       | NONE => raise Fail "Membership application not found"
 
 fun listApps status =
-    C.map (getDb ()) mkAppRow ($`SELECT id, name, rname, email, forward, uses, other, passwd, status, applied, confirmed, decided, msg
+    C.map (getDb ()) mkAppRow ($`SELECT id, name, rname, gname, email, forward, uses, other, passwd, status, applied, ipaddr, confirmed, decided, msg
                                 FROM MemberApp
                                 WHERE status = ^(statusToSql status)
                                 ORDER BY applied`)
@@ -62,7 +65,7 @@ fun mkVoteRow [id, name] = (C.intFromSql id, C.stringFromSql name)
 
 fun votes id = C.map (getDb ()) mkVoteRow ($`SELECT usr, name
                                             FROM AppVote JOIN WebUser ON usr = id
-                                            WHERE app = ^(C.intToSql id)
+                                            WHERE AppVote.app = ^(C.intToSql id)
                                             ORDER BY name`)
 
 fun vote (usr, app) = ignore (C.dml (getDb ()) ($`INSERT INTO AppVote (app, usr)
@@ -79,7 +82,9 @@ fun deny (app, msg) =
 
        val mail = Mail.mopen ()
     in
-       Mail.mwrite (mail, "From: Hcoop Application System <join@hcoop.net>\nTo: ");
+       Mail.mwrite (mail, "From: Hcoop Application System <join");
+       Mail.mwrite (mail, emailSuffix);
+       Mail.mwrite (mail, ">\nTo: ");
        Mail.mwrite (mail, #email entry);
        Mail.mwrite (mail, "\nCc: ");
        Mail.mwrite (mail, boardEmail);
@@ -97,11 +102,10 @@ fun approve (app, msg) =
 
        val mail = Mail.mopen ()
     in
-       Mail.mwrite (mail, "From: Hcoop Application System <join@hcoop.net>\nTo: ");
+       Mail.mwrite (mail, "To: ");
        Mail.mwrite (mail, #email entry);
-       Mail.mwrite (mail, "\nCc: ");
-       Mail.mwrite (mail, boardEmail);
-       Mail.mwrite (mail, "\nSubject: Application approved\n\nYour application for membership has been approved!  Welcome to hcoop!\n\n");
+       Mail.mwrite (mail, "\n");
+       Mail.mwrite (mail, Util.readFile "/home/hcoop/portal/welcome.txt");
        Mail.mwrite (mail, msg);
        OS.Process.isSuccess (Mail.mclose mail)
     end
@@ -116,4 +120,21 @@ fun abortAdd app =
                                SET status = 2
                                WHERE id = ^(C.intToSql app)`))
 
-end
\ No newline at end of file
+fun readFile fname =
+    let
+       val inf = TextIO.openIn fname
+
+       fun readLines lines =
+           case TextIO.inputLine inf of
+               NONE => String.concat (List.rev lines)
+             | SOME line => readLines (line :: lines)
+    in
+       readLines []
+       before TextIO.closeIn inf
+    end
+
+fun readTosBody () = readFile "/home/hcoop/public_html/tos.body.html"
+fun readTosAgree () = readFile "/home/hcoop/public_html/tos.agree.html"
+fun readTosMinorAgree () = readFile "/home/hcoop/public_html/tos.agree.minor.html"
+
+end