Newlines at ends of password files
[hcoop/zz_old/portal.git] / app.sml
diff --git a/app.sml b/app.sml
index 93a94eb..1941e2d 100644 (file)
--- a/app.sml
+++ b/app.sml
@@ -32,24 +32,27 @@ type app = { id : int, name : string, rname : string, gname : string option, ema
             forward : bool, uses : string, other : string,
             passwd : string, status : status, applied : C.timestamp, ipaddr : string option,
             confirmed : C.timestamp option, decided : C.timestamp option,
-            msg : string, unix_passwd : string}
+            msg : string, unix_passwd : string,
+            paypal : string option, checkout : string option }
 
 fun mkAppRow [id, name, rname, gname, email, forward, uses, other, passwd, status,
-             applied, ipaddr, confirmed, decided, msg, unix_passwd] =
+             applied, ipaddr, confirmed, decided, msg, unix_passwd, paypal, checkout] =
     { id = C.intFromSql id, name = C.stringFromSql name, rname = C.stringFromSql rname,
-      gname = (if C.isNull gname then NONE else SOME (C.stringFromSql gname)),
+      gname = Init.nullableFromSql 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, unix_passwd = C.stringFromSql unix_passwd}
+      ipaddr = Init.nullableFromSql C.stringFromSql ipaddr,
+      confirmed = Init.nullableFromSql C.timestampFromSql confirmed,
+      decided = Init.nullableFromSql C.timestampFromSql decided,
+      msg = C.stringFromSql msg, unix_passwd = C.stringFromSql unix_passwd,
+      paypal = Init.nullableFromSql C.stringFromSql paypal,
+      checkout = Init.nullableFromSql C.stringFromSql checkout}
   | mkAppRow r = rowError ("app", r)
 
 fun lookupApp id =
     case C.oneOrNoRows (getDb ()) ($`SELECT id, name, rname, gname, email, forward, uses, other, passwd, status, applied, ipaddr, confirmed, decided,
-                                           msg, unix_passwd
+                                           msg, unix_passwd, paypal, checkout
                                     FROM MemberApp
                                     WHERE id = ^(C.intToSql id)`) of
        SOME row => mkAppRow row
@@ -57,7 +60,7 @@ fun lookupApp id =
 
 fun listApps status =
     C.map (getDb ()) mkAppRow ($`SELECT id, name, rname, gname, email, forward, uses, other, passwd, status, applied, ipaddr, confirmed, decided,
-                                       msg, unix_passwd
+                                       msg, unix_passwd, paypal, checkout
                                 FROM MemberApp
                                 WHERE status = ^(statusToSql status)
                                   AND NOT (status = 2 AND decided < CURRENT_TIMESTAMP - INTERVAL '1 MONTH')
@@ -124,6 +127,7 @@ fun add app =
        val outf = TextIO.openOut (Config.passwordFiles ^ #name app)
     in
        TextIO.output (outf, #unix_passwd app);
+       TextIO.output1 (outf, #"\n");
        TextIO.closeOut outf
     end
 
@@ -162,4 +166,22 @@ 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"
 
+fun searchPaypal paypal =
+    C.map (getDb ()) mkAppRow ($`SELECT id, name, rname, gname, email, forward, uses, other, passwd, status, applied, ipaddr, confirmed, decided,
+                                       msg, unix_passwd, paypal, checkout
+                                FROM MemberApp
+                                WHERE paypal = ^(C.stringToSql (normEmail paypal))
+                                  AND status = 2
+                                  AND decided >= CURRENT_TIMESTAMP - INTERVAL '1 MONTH'
+                                ORDER BY applied`)
+
+fun searchCheckout checkout =
+    C.map (getDb ()) mkAppRow ($`SELECT id, name, rname, gname, email, forward, uses, other, passwd, status, applied, ipaddr, confirmed, decided,
+                                       msg, unix_passwd, paypal, checkout
+                                FROM MemberApp
+                                WHERE checkout = ^(C.stringToSql (normEmail checkout))
+                                  AND status = 2
+                                  AND decided >= CURRENT_TIMESTAMP - INTERVAL '1 MONTH'
+                                ORDER BY applied`)
+
 end