From f400231d6f611c83fdbe1df8ff29835a972db677 Mon Sep 17 00:00:00 2001 From: rich Date: Wed, 26 Jul 2006 13:19:49 +0000 Subject: [PATCH] If anonymous account creation isn't allowed, then don't print "Create account or log in". Should reduce the amount of clueless emails we get on the subject. --- scripts/lib/cocanwiki.ml | 20 +++++++++++++------- scripts/login_form.ml | 11 +++-------- scripts/page.ml | 7 ++++++- templates/page.html | 2 +- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/scripts/lib/cocanwiki.ml b/scripts/lib/cocanwiki.ml index ad625c1..1ce26cf 100644 --- a/scripts/lib/cocanwiki.ml +++ b/scripts/lib/cocanwiki.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki.ml,v 1.10 2006/03/28 16:24:08 rich Exp $ + * $Id: cocanwiki.ml,v 1.11 2006/07/26 13:19:51 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 @@ -31,7 +31,8 @@ open Cocanwiki_strings type host_t = { hostname : string; canonical_hostname : string; edit_anon : bool; - view_anon : bool } + view_anon : bool; + create_account_anon : bool; } (* Permissions and restrictions. * @@ -118,7 +119,8 @@ let register_script ?(restrict = []) ?(anonymous = true) run = (* Get the host ID, by comparing the Host: header with the hostnames * table in the database. *) - let hostid, hostname, canonical_hostname, edit_anon, view_anon = + let hostid, hostname, canonical_hostname, edit_anon, view_anon, + create_account_anon = let hostname = try Request.hostname r with Not_found -> @@ -133,13 +135,16 @@ let register_script ?(restrict = []) ?(anonymous = true) run = let rows = PGSQL(dbh) - "select h.id, h.canonical_hostname, h.edit_anon, h.view_anon + "select h.id, h.canonical_hostname, h.edit_anon, h.view_anon, + h.create_account_anon from hostnames hn, hosts h where hn.name = $hostname and hn.hostid = h.id" in match rows with - | [id, canonical_hostname, edit_anon, view_anon] -> - id, hostname, canonical_hostname, edit_anon, view_anon + | [id, canonical_hostname, edit_anon, view_anon, + create_account_anon] -> + id, hostname, canonical_hostname, edit_anon, view_anon, + create_account_anon | [] -> error ~back_button:true ~title:"Unknown website" dbh (-1l) q @@ -154,7 +159,8 @@ let register_script ?(restrict = []) ?(anonymous = true) run = let host = { hostname = hostname; canonical_hostname = canonical_hostname; edit_anon = edit_anon; - view_anon = view_anon } in + view_anon = view_anon; + create_account_anon = create_account_anon; } in (* Look for the user's cookie, and determine from this the user * object. diff --git a/scripts/login_form.ml b/scripts/login_form.ml index 39fbb06..9d2ed94 100644 --- a/scripts/login_form.ml +++ b/scripts/login_form.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: login_form.ml,v 1.7 2006/03/28 13:20:00 rich Exp $ + * $Id: login_form.ml,v 1.8 2006/07/26 13:19:49 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 @@ -28,7 +28,8 @@ open Cocanwiki open Cocanwiki_template open Cocanwiki_strings -let run r (q : cgi) dbh hostid _ _ = +let run r (q : cgi) dbh hostid + { create_account_anon = create_account_anon } _ = let template = get_template dbh hostid "login_form.html" in let redirect = try q#param "redirect" with Not_found -> "" in @@ -43,12 +44,6 @@ let run r (q : cgi) dbh hostid _ _ = let username = try q#param "username" with Not_found -> "" in template#set "username" username; - let create_account_anon = - List.hd ( - PGSQL(dbh) "select create_account_anon from hosts - where id = $hostid" - ) in - template#conditional "create_account_anon" create_account_anon; q#template template diff --git a/scripts/page.ml b/scripts/page.ml index 7001a08..d1e8b09 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: page.ml,v 1.46 2006/07/26 13:11:25 rich Exp $ + * $Id: page.ml,v 1.47 2006/07/26 13:19:49 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 @@ -299,6 +299,11 @@ let run r (q : cgi) dbh hostid t#conditional "user_logged_in" true; t#set "username" username); + (* Can anonymous users create accounts? If not them we don't + * want to offer to create accounts for them. + *) + t#conditional "create_account_anon" host.create_account_anon; + (* If logged in, we want to update the recently_visited table. *) if pageid <> None then ( match user with diff --git a/templates/page.html b/templates/page.html index 2f40a89..76c8d49 100644 --- a/templates/page.html +++ b/templates/page.html @@ -47,7 +47,7 @@