Added the framework to allow us to populate standards parts of the
[cocanwiki.git] / scripts / login_form.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: login_form.ml,v 1.2 2004/09/08 15:46:53 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open Cocanwiki
13 open Cocanwiki_template
14 open Cocanwiki_strings
15
16 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
17   let template = get_template dbh hostid "login_form.html" in
18
19   let redirect = try q#param "redirect" with Not_found -> "" in
20
21   if string_is_whitespace redirect then
22     template#conditional "has_redirect" false
23   else (
24     template#conditional "has_redirect" true;
25     template#set "redirect" redirect
26   );
27
28   let sth = dbh#prepare_cached "select create_account_anon from hosts
29                                  where id = ?" in
30   sth#execute [`Int hostid];
31
32   let create_account_anon =
33     match sth#fetch1 () with
34         [ `Bool b ] -> b
35       | _ -> assert false in
36
37   template#conditional "create_account_anon" create_account_anon;
38
39   q#template template
40
41 let () =
42   register_script run