1 (* COCANWIKI - a wiki written in Objective CAML.
2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: delete_user.ml,v 1.3 2004/10/23 15:00:14 rich Exp $
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
30 let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} self =
31 if q#param_true "cancel" then (
32 (* Request cancelled. *)
33 q#redirect ("http://" ^ hostname ^ "/_users");
37 let userid = int_of_string (q#param "userid") in
39 (* Check userid belongs to host. The statements below wouldn't
40 * enforce this correctly ...
43 dbh#prepare_cached "select 1 from users where id = ? and hostid = ?" in
44 sth#execute [`Int userid; `Int hostid];
46 assert (sth#fetch1int () = 1);
48 (* Can't delete self! *)
51 | User (id, _, _) when id = userid ->
52 error ~back_button:true ~title:"Delete own account"
53 q "You cannot delete your own user account.";
57 (* Delete the user. *)
59 dbh#prepare_cached "delete from recently_visited
60 where userid = ? and hostid = ?" in
61 sth#execute [`Int userid; `Int hostid];
64 dbh#prepare_cached "delete from pending_email_changes
66 sth#execute [`Int userid];
69 let sth = dbh#prepare_cached "delete from usercookies where userid = ?" in
70 sth#execute [`Int userid];
72 let sth = dbh#prepare_cached "update pages set logged_user = null
73 where logged_user = ? and hostid = ?" in
74 sth#execute [`Int userid; `Int hostid];
77 dbh#prepare_cached "delete from users where id = ? and hostid = ?" in
78 sth#execute [`Int userid; `Int hostid];
82 ok ~title:"Account deleted" ~buttons:[ok_button "/_users"]
83 q "That user account was deleted."
86 register_script ~restrict:[CanManageUsers] run