(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_user.ml,v 1.11 2006/03/27 18:09:46 rich Exp $
+ * $Id: edit_user.ml,v 1.13 2006/07/26 16:34:18 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
(* Get the user's original name. If we're going to change the
* name, we need to do additional checks.
*)
- let sth = dbh#prepare_cached "select name from users
- where hostid = ? and id = ?" in
- sth#execute [Some hostid; Some userid];
- let original_name = sth#fetch1string () in
+ let original_name =
+ List.hd (
+ PGSQL(dbh)
+ "select name from users where hostid = $hostid and id = $userid"
+ ) in
let name = trim (q#param "name") in
);
(* Check it's not a duplicate, then change it. *)
- let sth = dbh#prepare_cached "select id from users
- where hostid = ? and name = ?" in
- sth#execute [Some hostid; Some name];
+ let rows = PGSQL(dbh)
+ "select 1 from users where hostid = $hostid and name = $name" in
- (try
- sth#fetch1 ();
- error ~back_button:true ~title:"Username already taken"
- dbh hostid q
- ("That username has already been taken by another user.");
- return ()
- with
- Not_found -> ());
+ (match rows with
+ | [Some 1l] ->
+ error ~back_button:true ~title:"Username already taken"
+ dbh hostid q
+ ("That username has already been taken by another user.");
+ return ()
+ | _ -> ()
+ );
- let sth = dbh#prepare_cached "update users set name = ?
- where hostid = ? and id = ?" in
- sth#execute [Some name; Some hostid; Some userid]
+ PGSQL(dbh) "update users set name = $name
+ where hostid = $hostid and id = $userid"
);
(* Change permissions. *)
let can_manage_site = q#param_true "can_manage_site" in
let can_edit_global_css = q#param_true "can_edit_global_css" in
let can_import_mail = q#param_true "can_import_mail" in
+ let can_edit_macros = q#param_true "can_edit_macros" in
(* Trying to remove manage users permission from self? *)
(match can_manage_users, self with
return ()
| _ -> ());
- let sth = dbh#prepare_cached "update users set
- can_edit = ?, can_manage_users = ?,
- can_manage_contacts = ?,
- can_manage_site = ?,
- can_edit_global_css = ?,
- can_import_mail = ?
- where hostid = ? and id = ?" in
- sth#execute [`Bool can_edit; `Bool can_manage_users;
- `Bool can_manage_contacts; `Bool can_manage_site;
- `Bool can_edit_global_css; `Bool can_import_mail;
- Some hostid; Some userid];
+ PGSQL(dbh)
+ "update users set
+ can_edit = $can_edit, can_manage_users = $can_manage_users,
+ can_manage_contacts = $can_manage_contacts,
+ can_manage_site = $can_manage_site,
+ can_edit_global_css = $can_edit_global_css,
+ can_import_mail = $can_import_mail,
+ can_edit_macros = $can_edit_macros
+ where hostid = $hostid and id = $userid";
(* Finish up. *)
PGOCaml.commit dbh;