(* 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.1 2004/10/23 15:00:14 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
open Cocanwiki
open Cocanwiki_ok
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
+let run r (q : cgi) dbh hostid _ _ =
(* 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 [`String key];
+ let rows = PGSQL(dbh) "select userid, email from pending_email_changes
+ where key = $key" in
let userid, email =
- try
- (match sth#fetch1 () with
- [ `Int userid; `String email ] -> userid, email
- | _ -> assert false)
- with
- Not_found ->
- error ~title:"Already verified"
- 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 [`String key];
+ PGSQL(dbh) "delete from pending_email_changes where key = $key";
+ PGSQL(dbh) "update users set email = $email where id = $userid";
- let sth = dbh#prepare_cached "update users set email = ? where id = ?" in
- sth#execute [`String email; `Int userid];
-
- dbh#commit ();
+ PGOCaml.commit dbh;
ok ~title:"Email address verified"
- 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