X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Fuser_prefs.ml;h=0cc2db0757e05f97744340aaa66cff75bf978121;hb=cd059731a60fd3d4dcf426430ad26ff227b91910;hp=8884c83264574c89a89248867f197136223f605b;hpb=295f2cde3f43ccf7f775d39b95925e10aa4c37cb;p=cocanwiki.git diff --git a/scripts/user_prefs.ml b/scripts/user_prefs.ml index 8884c83..0cc2db0 100644 --- a/scripts/user_prefs.ml +++ b/scripts/user_prefs.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: user_prefs.ml,v 1.5 2005/03/31 14:24:04 rich Exp $ + * $Id: user_prefs.ml,v 1.8 2006/03/28 16:24:08 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 @@ -29,7 +29,7 @@ open Cocanwiki_ok open Cocanwiki_template open Cocanwiki_strings -let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname=hostname} user = +let run r (q : cgi) dbh hostid {hostname=hostname} user = let email_change_template = _get_template "user_prefs_email_change.txt" in (* Get the fields. *) @@ -42,11 +42,9 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname=hostname} user = | User (userid, _, _, _) -> userid in (* Update the preferences fields. *) - let sth = - dbh#prepare_cached "update users set email_notify = ? - where hostid = ? and id = ?" in - sth#execute [`Bool email_notify; - `Int hostid; `Int userid]; + PGSQL(dbh) + "update users set email_notify = $email_notify + where hostid = $hostid and id = $userid"; (* Have we changed the email address? *) let confirm_needed = @@ -54,28 +52,27 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname=hostname} user = (* Set the email field in the database to null. No need for * any confirmation. *) - let sth = dbh#prepare_cached "update users set email = null - where hostid = ? and id = ?" in - sth#execute [`Int hostid; `Int userid]; + PGSQL(dbh) "update users set email = null + where hostid = $hostid and id = $userid"; false ) else ( (* Is the new email address different from the one currently recorded * in the database? *) - let sth = dbh#prepare_cached "select ? <> coalesce (email, '') - from users where hostid = ? and id = ?" in - sth#execute [`String new_email; `Int hostid; `Int userid]; - - let changed = - match sth#fetch1 () with [ `Bool b ] -> b | _ -> assert false in + let changed = Option.get ( + List.hd ( + PGSQL(dbh) "select $new_email <> coalesce (email, '') + from users where hostid = $hostid and id = $userid" + ) + ) in if changed then ( let key = random_sessionid () in (* Changed, so we add to the pending_email_changes table. *) - let sth = dbh#prepare_cached "insert into pending_email_changes - (key, userid, email) values (?, ?, ?)" in - sth#execute [`String key; `Int userid; `String new_email]; + PGSQL(dbh) "insert into pending_email_changes + (key, userid, email) + values ($key, $userid, $new_email)"; (* Send the confirm email. *) email_change_template#set "hostname" hostname; @@ -90,16 +87,16 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname=hostname} user = ) in (* Good place to remove old rows in the pending_email_changes table. *) - let sth = dbh#prepare_cached "delete from pending_email_changes - where change_date - current_date > 7" in - sth#execute []; + PGSQL(dbh) "delete from pending_email_changes + where change_date - current_date > 7"; (* Commit and finish off. *) - dbh#commit (); + PGOCaml.commit dbh; let buttons = [ ok_button "/_userprefs" ] in ok ~title:"Preferences updated" ~buttons - q ("Your user preferences were updated. " ^ + dbh hostid q + ("Your user preferences were updated. " ^ if confirm_needed then ("Because you changed your email address, we have sent a " ^ "confirmation email to your new address. You will need to " ^