Don't forget the date\!
[cocanwiki.git] / scripts / delete_user.ml
index da705f5..653e7ed 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: delete_user.ml,v 1.5 2005/11/24 14:54:11 rich Exp $
+ * $Id: delete_user.ml,v 1.8 2006/12/06 09:46:57 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
@@ -27,60 +27,43 @@ open Printf
 open Cocanwiki
 open Cocanwiki_ok
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} self =
-  if q#param_true "cancel" then (
+let run r (q : cgi) dbh hostid {hostname = hostname} self =
+  if q#param_true "cancel" then
     (* Request cancelled. *)
     q#redirect ("http://" ^ hostname ^ "/_users");
-    return ()
-  );
 
-  let userid = int_of_string (q#param "userid") in
+  let userid = Int32.of_string (q#param "userid") in
 
   (* Check userid belongs to host.  The statements below wouldn't
    * enforce this correctly ...
    *)
-  let sth =
-    dbh#prepare_cached "select 1 from users where id = ? and hostid = ?" in
-  sth#execute [`Int userid; `Int hostid];
-
-  assert (sth#fetch1int () = 1);
+  let rows =
+    PGSQL(dbh) "select 1 from users where id = $userid and hostid = $hostid" in
+  assert (rows = [Some 1l]);
 
   (* Can't delete self! *)
   let () =
     match self with
       | User (id, _, _, _) when id = userid ->
          error ~back_button:true ~title:"Delete own account"
-           dbh hostid q "You cannot delete your own user account.";
+           dbh hostid q "You cannot delete your own user account.";
          return ()
       | _ -> () in
 
   (* Delete the user. *)
-  let sth =
-    dbh#prepare_cached "delete from recently_visited
-                         where userid = ? and hostid = ?" in
-  sth#execute [`Int userid; `Int hostid];
-
-  let sth =
-    dbh#prepare_cached "delete from pending_email_changes
-                         where userid = ?" in
-  sth#execute [`Int userid];
-
-
-  let sth = dbh#prepare_cached "delete from usercookies where userid = ?" in
-  sth#execute [`Int userid];
-
-  let sth = dbh#prepare_cached "update pages set logged_user = null
-                                 where logged_user = ? and hostid = ?" in
-  sth#execute [`Int userid; `Int hostid];
+  PGSQL(dbh) "delete from recently_visited
+               where userid = $userid and hostid = $hostid";
 
-  let sth =
-    dbh#prepare_cached "delete from users where id = ? and hostid = ?" in
-  sth#execute [`Int userid; `Int hostid];
+  PGSQL(dbh) "delete from pending_email_changes where userid = $userid";
+  PGSQL(dbh) "delete from usercookies where userid = $userid";
+  PGSQL(dbh) "update pages set logged_user = null
+               where logged_user = $userid and hostid = $hostid";
+  PGSQL(dbh) "delete from users where id = $userid and hostid = $hostid";
 
-  dbh#commit ();
+  PGOCaml.commit dbh;
 
   ok ~title:"Account deleted" ~buttons:[ok_button "/_users"]
-    dbh hostid q "That user account was deleted."
+    dbh hostid q "That user account was deleted."
 
 let () =
   register_script ~restrict:[CanManageUsers] run