Changes done on the Mac.
[cocanwiki.git] / scripts / invite_user.ml
index 66aa47b..19bd170 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: invite_user.ml,v 1.6 2006/03/27 18:09:46 rich Exp $
+ * $Id: invite_user.ml,v 1.7 2006/03/28 13:20:00 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -61,41 +61,39 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
    *)
   List.iter
     (fun email ->
-       let sth = dbh#prepare_cached "select id, invite from users
-                                      where hostid = ? and
-                                            (email = ? or name = ?)" in
-       sth#execute [Some hostid; Some email; Some email];
+       let rows = PGSQL(dbh) "select id, invite from users
+                               where hostid = $hostid and
+                               (email = $email or name = $email)" in
 
        let body =
-        try
-          (match sth#fetch1 () with
-               [ Some userid; None ] ->
-                 (* Existing user account - send reminder. *)
-                 template_exists#set "username" username;
-                 template_exists#set "hostname" hostname;
-                 template_exists#to_string
-
-             | [ Some userid; Some invite ] ->
-                 (* Existing user account - resend the invite. *)
-                 template#set "username" username;
-                 template#set "hostname" hostname;
-                 template#set "invite" invite;
-                 template#to_string
-
-             | _ -> assert false)
-        with
-            Not_found ->
-              (* Add user account. *)
-              let invite = random_sessionid () in
-              let sth = dbh#prepare_cached "insert into users (hostid, name,
-                 password, email, invite) values (?, ?, ?, ?, ?)" in
-              sth#execute [Some hostid; Some email; Some invite;
-                           Some email; Some invite];
-
-              template#set "username" username;
-              template#set "hostname" hostname;
-              template#set "invite" invite;
-              template#to_string in
+        match rows with
+        | [ userid, None ] ->
+            (* Existing user account - send reminder. *)
+            template_exists#set "username" username;
+            template_exists#set "hostname" hostname;
+            template_exists#to_string
+
+        | [ userid, Some invite ] ->
+            (* Existing user account - resend the invite. *)
+            template#set "username" username;
+            template#set "hostname" hostname;
+            template#set "invite" invite;
+            template#to_string
+
+        | [] ->
+            (* Add user account. *)
+            let invite = random_sessionid () in
+            PGSQL(dbh)
+              "insert into users (hostid, name,
+                  password, email, invite) values ($hostid, $email, $invite,
+                  $email, $invite)";
+
+            template#set "username" username;
+            template#set "hostname" hostname;
+            template#set "invite" invite;
+            template#to_string
+
+        | _ -> assert false in
 
        (* Send the email. *)
        Sendmail.send_mail ~subject ~to_addr:[email] ~from body