(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: invite_user_confirm.ml,v 1.5 2006/03/27 18:09:46 rich Exp $
+ * $Id: invite_user_confirm.ml,v 1.8 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
let invite = q#param "invite" in
(* Verify the username, invite combination. *)
- let sth = dbh#prepare_cached "select email, id from users
- where hostid = ? and
- name = ? and invite = ?" in
- sth#execute [Some hostid; Some username; Some invite];
+ let rows = PGSQL(dbh) "select email, id from users
+ where hostid = $hostid and
+ name = $username and invite = $invite" in
let email, userid =
- try
- match sth#fetch1 () with
- [ Some email; Some userid ] -> Some email, userid
- | [ None; Some userid ] -> None, userid
- | _ -> assert false
- with Not_found ->
- error ~title:"Already signed up"
- dbh hostid q "It looks like you have already used your invitation.";
- return () in
+ match rows with
+ | [ Some email, userid ] -> Some email, userid
+ | [ None, userid ] -> None, userid
+ | [] ->
+ error ~title:"Already signed up"
+ dbh hostid q "It looks like you have already used your invitation.";
+ return ()
+ | _ -> assert false in
let password1 = q#param "password1" in
let password2 = q#param "password2" in
let password = password1 in
(* Change the password. *)
- let sth =
- dbh#prepare_cached
- "update users set password = ?, invite = null,
- force_password_change = false
- where hostid = ? and id = ?" in
- sth#execute [Some password; Some hostid; Some userid];
+ PGSQL(dbh)
+ "update users set password = $password, invite = null,
+ force_password_change = false
+ where hostid = $hostid and id = $userid";
(* Send email to this user. *)
(match email with
let body = template#to_string in
let subject = "Your new account details" in
- Sendmail.send_mail ~to_addr:[email] ~subject body);
+
+ let to_addrs = [ "", email ] in
+ let content_type =
+ "text/plain", ["charset", Mimestring.mk_param "UTF-8"] in
+
+ let msg = Netsendmail.compose ~to_addrs ~subject ~content_type body in
+ Netsendmail.sendmail msg);
PGOCaml.commit dbh;