Added machine-parsable links database, per-page links and page source.
[cocanwiki.git] / scripts / invite_user.ml
index a2d3bab..bca130f 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: invite_user.ml,v 1.1 2004/10/14 15:57:15 rich Exp $
+ * $Id: invite_user.ml,v 1.2 2004/10/23 15:00:15 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
@@ -68,32 +68,40 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
    *)
   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. *)