(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: email_change.ml,v 1.3 2006/03/27 18:09:46 rich Exp $
+ * $Id: email_change.ml,v 1.5 2006/12/06 09:46:57 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 key in the pending_email_changes table. *)
let key = q#param "key" in
- let sth = dbh#prepare_cached "select userid, email from pending_email_changes
- where key = ?" in
- sth#execute [Some key];
+ let rows = PGSQL(dbh) "select userid, email from pending_email_changes
+ where key = $key" in
let userid, email =
- try
- (match sth#fetch1 () with
- [ Some userid; Some email ] -> userid, email
- | _ -> assert false)
- with
- Not_found ->
- error ~title:"Already verified"
- dbh hostid q
- ("It looks like you have already verified this email address.");
- return () in
+ match rows with
+ | [ row ] -> row
+ | [] ->
+ error ~title:"Already verified"
+ r dbh hostid q
+ ("It looks like you have already verified this email address.");
+ return ()
+ | _ -> assert false in
(* Update the database. *)
- let sth = dbh#prepare_cached "delete from pending_email_changes
- where key = ?" in
- sth#execute [Some key];
-
- let sth = dbh#prepare_cached "update users set email = ? where id = ?" in
- sth#execute [Some email; Some userid];
+ PGSQL(dbh) "delete from pending_email_changes where key = $key";
+ PGSQL(dbh) "update users set email = $email where id = $userid";
PGOCaml.commit dbh;
ok ~title:"Email address verified"
- dbh hostid q "Thank you for verifying your new email address."
+ r dbh hostid q "Thank you for verifying your new email address."
let () =
register_script run