Change subject line so it shows the name of the site.
[cocanwiki.git] / scripts / email_change.ml
index 702bee8..1d254a8 100644 (file)
@@ -1,7 +1,7 @@
 (* 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.4 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
@@ -27,37 +27,31 @@ open Printf
 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"
+         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."
+    dbh hostid q "Thank you for verifying your new email address."
 
 let () =
   register_script run