Changes done on the Mac.
[cocanwiki.git] / scripts / invite_user_confirm.ml
index e44265c..9db853a 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_confirm.ml,v 1.5 2006/03/27 18:09:46 rich Exp $
+ * $Id: invite_user_confirm.ml,v 1.6 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
@@ -36,21 +36,19 @@ let run r (q : cgi) dbh hostid { hostname = hostname } _ =
   let invite = q#param "invite" in
 
   (* Verify the username, invite combination. *)
-  let sth = dbh#prepare_cached "select email, id from users
-                                 where hostid = ? and
-                                       name = ? and invite = ?" in
-  sth#execute [Some hostid; Some username; Some invite];
+  let rows = PGSQL(dbh) "select email, id from users
+                          where hostid = $hostid and
+                                name = $username and invite = $invite" in
 
   let email, userid =
-    try
-      match sth#fetch1 () with
-         [ Some email; Some userid ] -> Some email, userid
-       | [ None; Some userid ] -> None, userid
-       | _ -> assert false
-    with Not_found ->
-      error ~title:"Already signed up"
-        dbh hostid q "It looks like you have already used your invitation.";
-      return () in
+    match rows with
+    | [ Some email; userid ] -> Some email, userid
+    | [ None; userid ] -> None, userid
+    | [] ->
+       error ~title:"Already signed up"
+          dbh hostid q "It looks like you have already used your invitation.";
+       return ()
+    | _ -> assert false in
 
   let password1 = q#param "password1" in
   let password2 = q#param "password2" in
@@ -70,12 +68,10 @@ let run r (q : cgi) dbh hostid { hostname = hostname } _ =
   let password = password1 in
 
   (* Change the password. *)
-  let sth =
-    dbh#prepare_cached
-      "update users set password = ?, invite = null,
-                        force_password_change = false
-        where hostid = ? and id = ?" in
-  sth#execute [Some password; Some hostid; Some userid];
+  PGSQL(dbh)
+    "update users set password = $password, invite = null,
+                      force_password_change = false
+      where hostid = $hostid and id = $userid";
 
   (* Send email to this user. *)
   (match email with