X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Fedit_user.ml;h=bfbd1911a6126ae49b74e6722114a15741de4e20;hb=262f6a0c34949247ba6b78399b787e693da38d86;hp=d9cb59c4e35e26de45900244915fb9aeba7ea9d6;hpb=e828b148d6338765d7f5ca8f10567d5d9ef00548;p=cocanwiki.git diff --git a/scripts/edit_user.ml b/scripts/edit_user.ml index d9cb59c..bfbd191 100644 --- a/scripts/edit_user.ml +++ b/scripts/edit_user.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit_user.ml,v 1.10 2005/11/24 14:54:12 rich Exp $ + * $Id: edit_user.ml,v 1.12 2006/03/27 19:10:29 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 @@ -28,16 +28,17 @@ open Cocanwiki open Cocanwiki_strings open Cocanwiki_ok -let run r (q : cgi) (dbh : Dbi.connection) hostid _ self = - let userid = int_of_string (q#param "userid") in +let run r (q : cgi) dbh hostid _ self = + let userid = Int32.of_string (q#param "userid") in (* 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 [`Int hostid; `Int 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 @@ -49,22 +50,20 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ self = ); (* 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 [`Int hostid; `String 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 [`String name; `Int hostid; `Int userid] + PGSQL(dbh) "update users set name = $name + where hostid = $hostid and id = $userid" ); (* Change permissions. *) @@ -86,20 +85,17 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ self = 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; - `Int hostid; `Int 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 + where hostid = $hostid and id = $userid"; (* Finish up. *) - dbh#commit (); + PGOCaml.commit dbh; let buttons = [ ok_button "/_users" ] in ok ~buttons ~title:"Saved"