X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Finvite_user.ml;h=2895d78598e23f24cca4b3c21754d0958db154b0;hb=32f71ff9f960ecb191f256a6cfc11a3f2c0c0cf7;hp=a2d3bab0d7d19a1ac0adf8f1a8de3fe02e608b1e;hpb=0bbc87f2b064e8080f18e77ffcadcd6348ecd9be;p=cocanwiki.git diff --git a/scripts/invite_user.ml b/scripts/invite_user.ml index a2d3bab..2895d78 100644 --- a/scripts/invite_user.ml +++ b/scripts/invite_user.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: invite_user.ml,v 1.1 2004/10/14 15:57:15 rich Exp $ + * $Id: invite_user.ml,v 1.3 2004/10/30 10:16:10 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 @@ -44,56 +44,57 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user = return () ); - let userid, username = match user with - User (userid, username, _) -> userid, username + let userid, username, email = match user with + User (userid, username, _, prefs) -> userid, username, prefs.email | _ -> assert false in let subject = username ^ " has invited you to join " ^ hostname in - (* Get user's own email address, which will be the return address - * for the email. - *) - let sth = dbh#prepare_cached "select email from users - where hostid = ? and id = ?" in - sth#execute [`Int hostid; `Int userid]; - + (* Get a suitable return address for the email. *) let from = - match sth#fetch1 () with - [ `String email ] -> email - | [ `Null ] -> "service@merjis.com" - | _ -> assert false in + match email with + | Some email -> email + | None -> "service@merjis.com" in (* Add user accounts for these new users. For users who are already * registered, we'll send reminder emails. *) List.iter (fun email -> - let sth = dbh#prepare_cached "select id from users + let sth = dbh#prepare_cached "select id, invite from users where hostid = ? and (email = ? or name = ?)" in sth#execute [`Int hostid; `String email; `String email]; - let userid = try Some (sth#fetch1int ()) with Not_found -> None in - let body = - match userid with - Some userid -> - (* Existing user account - send reminder. *) - template_exists#set "username" username; - template_exists#set "hostname" hostname; - template_exists#to_string - - | None -> + try + (match sth#fetch1 () with + [ `Int userid; `Null ] -> + (* Existing user account - send reminder. *) + template_exists#set "username" username; + template_exists#set "hostname" hostname; + template_exists#to_string + + | [ `Int userid; `String invite ] -> + (* Existing user account - resend the invite. *) + template#set "username" username; + template#set "hostname" hostname; + template#set "invite" invite; + template#to_string + + | _ -> assert false) + with + Not_found -> (* Add user account. *) - let password = random_sessionid () in + let invite = random_sessionid () in let sth = dbh#prepare_cached "insert into users (hostid, name, - password, email) values (?, ?, ?, ?)" in - sth#execute [`Int hostid; `String email; `String password; - `String email]; + password, email, invite) values (?, ?, ?, ?, ?)" in + sth#execute [`Int hostid; `String email; `String invite; + `String email; `String invite]; template#set "username" username; template#set "hostname" hostname; - template#set "password" password; + template#set "invite" invite; template#to_string in (* Send the email. *)