list: Point people at wiki for instructions on using a custom web domain
[hcoop/zz_old/portal.git] / app / app.sml
index f142e1b..96d9f47 100644 (file)
@@ -93,21 +93,29 @@ fun sendMail (to, subj, intro, footer, id) =
     end
 
 type application = { name : string, rname : string, gname : string option, email : string,
-                    forward : bool, uses : string, other : string }
+                    forward : bool, uses : string, other : string,
+                    paypal : string option, checkout : string option }
 
 fun randomPassword () =
     let
-       val proc = Unix.execute ("/usr/bin/apg", ["/usr/bin/apg", "-n", "1", "-m", "10"])
+       val proc = Unix.execute ("/usr/bin/pwgen", ["-cCnB", "8", "1"])
     in
        case TextIO.inputLine (Unix.textInstreamOf proc) of
-           NONE => raise Fail "Couldn't execute apg"
+           NONE => raise Fail "Couldn't execute pwgen"
          | SOME line =>
            case String.tokens Char.isSpace line of
                [s] => s
-             | _ => raise Fail "Couldn't parse output of apg"
+             | _ => raise Fail "Couldn't parse output of pwgen"
     end
 
-fun apply {name, rname, gname, email, forward, uses, other} =
+val allLower = CharVector.map Char.toLower
+
+fun emailToSql so =
+    case so of
+       NONE => "NULL"
+      | SOME s => C.stringToSql (allLower s)
+
+fun apply {name, rname, gname, email, forward, uses, other, paypal, checkout} =
     let
        val db = getDb ()
     in
@@ -118,12 +126,14 @@ fun apply {name, rname, gname, email, forward, uses, other} =
                val passwd = Int.toString (Int.abs (Random.randInt (!rnd)))
                val unix_passwd = randomPassword ()
            in
-               C.dml db ($`INSERT INTO MemberApp (id, name, rname, gname, email, forward, uses, other, passwd, status, applied, msg, unix_passwd)
+               C.dml db ($`INSERT INTO MemberApp (id, name, rname, gname, email, forward, uses, other, passwd,
+                                                  status, applied, msg, unix_passwd, paypal, checkout)
                            VALUES (^(C.intToSql id), ^(C.stringToSql name), ^(C.stringToSql rname),
                                    ^(case gname of NONE => "NULL" | SOME gname => C.stringToSql gname),
                                    ^(C.stringToSql email), ^(C.boolToSql forward), ^(C.stringToSql uses),
                                    ^(C.stringToSql other), ^(C.stringToSql passwd), 0, CURRENT_TIMESTAMP,
-                                   '', ^(C.stringToSql unix_passwd))`);
+                                   '', ^(C.stringToSql unix_passwd),
+                                   ^(emailToSql paypal), ^(emailToSql checkout))`);
                if sendMail (email, "Confirm membership application",
                             "We've received a request to join the Internet Hosting Cooperative (hcoop.net) with this e-mail address.",
                          fn mwrite => (mwrite ("To confirm this application, visit ");