join: use generic sendmail instead of exim4
[hcoop/portal.git] / app / app.sml
index 96d9f47..12abe57 100644 (file)
@@ -1,8 +1,8 @@
 structure App :> APP =
 struct
 
-val baseUrl = "https://join.hcoop.net/join/"
-val portalUrl = "https://members2.hcoop.net/portal/"
+val baseUrl = "https://join3.hcoop.net/join/"
+val portalUrl = Config.urlPrefix
 
 open Sql
 
@@ -14,7 +14,7 @@ val rnd = ref (Random.rand (0, 0))
 
 fun init () = 
     let
-       val c = C.conn "dbname='hcoop_hcoop'"
+       val c = C.conn Config.dbstring
     in
        db := SOME c;
        C.dml c "BEGIN";
@@ -46,9 +46,9 @@ fun readFile fname =
        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"
+fun readTosBody () = readFile (Config.staticFilesRoot ^ "tos.body.html")
+fun readTosAgree () = readFile (Config.staticFilesRoot ^ "tos.agree.html")
+fun readTosMinorAgree () = readFile (Config.staticFilesRoot ^ "tos.agree.minor.html")
 
 fun sendMail (to, subj, intro, footer, id) =
     let
@@ -62,7 +62,7 @@ fun sendMail (to, subj, intro, footer, id) =
                 C.stringFromSql other)
              | _ => raise Fail "Bad sendMail row"
 
-       val proc = Unix.execute ("/usr/sbin/exim4", ["-t"])
+       val proc = Unix.execute ("/usr/sbin/sendmail", ["-t"])
        fun mwrite s = TextIO.output (Unix.textOutstreamOf proc, s)
     in
        mwrite ("From: Hcoop Application System <join@hcoop.net>\nTo: ");
@@ -159,10 +159,11 @@ fun validHost s =
 fun validDomain s =
     size s > 0 andalso size s < 100 andalso List.all validHost (String.fields (fn ch => ch = #".") s)
 
-fun validUser s =
-    size s > 0 andalso size s < 50 andalso List.all
-                                              (fn ch => isIdent ch orelse ch = #"." orelse ch = #"_" orelse ch = #"-" orelse ch = #"+")
-                                              (String.explode s)
+fun validUsername name =
+    size name <= 12
+    andalso size name > 0
+    andalso Char.isLower (String.sub (name, 0))
+    andalso CharVector.all Char.isAlphaNum name
 
 fun validEmailUser s =
     size s > 0 andalso size s < 50 andalso List.all
@@ -175,7 +176,9 @@ fun validEmail s =
        | _ => false)
 
 fun userExists name =
-    (Posix.SysDB.getpwnam name; true) handle OS.SysErr _ => false
+    case C.oneOrNoRows (getDb ()) ($`SELECT id FROM WebUser WHERE name = ^(C.stringToSql name)`) of
+       SOME _ => true
+      | NONE => (Posix.SysDB.getpwnam name; true) handle OS.SysErr _ => false
 
 fun confirm (id, passwd) =
     let