(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: user_prefs.ml,v 1.7 2006/03/27 18:09:47 rich Exp $
+ * $Id: user_prefs.ml,v 1.9 2006/07/31 09:49:43 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
| 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;
- Some hostid; Some 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 =
(* 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 [Some hostid; Some 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 [Some new_email; Some hostid; Some 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 [Some key; Some userid; Some 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;
let body = email_change_template#to_string in
let subject = "Please verify your new email address at " ^ hostname in
- Sendmail.send_mail ~subject ~to_addr:[new_email] body
+
+ let content_type =
+ "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+ let to_addrs = [ "", new_email ] in
+
+ let msg = Netsendmail.compose ~subject ~to_addrs ~content_type body in
+ Netsendmail.sendmail msg
);
changed
) 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. *)
PGOCaml.commit dbh;