From: rich Date: Wed, 8 Sep 2004 10:42:19 +0000 (+0000) Subject: User management started. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=1de828f0dde14a10388658c2b2893a0477f7e653;p=cocanwiki.git User management started. --- diff --git a/cocanwiki.sql b/cocanwiki.sql index 85f072f..9471c7e 100644 --- a/cocanwiki.sql +++ b/cocanwiki.sql @@ -37,7 +37,8 @@ CREATE TABLE pages ( hostid integer NOT NULL, logged_ip text, redirect text, - css text + css text, + logged_user integer ); @@ -348,7 +349,7 @@ CREATE UNIQUE INDEX files_name_uq ON files USING btree (hostid, name); -- --- TOC entry 40 (OID 540831) +-- TOC entry 41 (OID 540831) -- Name: users_name_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -356,6 +357,14 @@ CREATE UNIQUE INDEX users_name_uq ON users USING btree (hostid, name); -- +-- TOC entry 40 (OID 540946) +-- Name: users_id_uq; Type: INDEX; Schema: public; Owner: rich +-- + +CREATE UNIQUE INDEX users_id_uq ON users USING btree (hostid, id); + + +-- -- TOC entry 29 (OID 536012) -- Name: pages_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -401,7 +410,7 @@ ALTER TABLE ONLY files -- --- TOC entry 41 (OID 540825) +-- TOC entry 42 (OID 540825) -- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -410,7 +419,7 @@ ALTER TABLE ONLY users -- --- TOC entry 44 (OID 536029) +-- TOC entry 47 (OID 536029) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -419,7 +428,7 @@ ALTER TABLE ONLY contents -- --- TOC entry 46 (OID 536384) +-- TOC entry 49 (OID 536384) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -428,7 +437,7 @@ ALTER TABLE ONLY hostnames -- --- TOC entry 45 (OID 536394) +-- TOC entry 48 (OID 536394) -- Name: hosts_hostname_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -437,7 +446,7 @@ ALTER TABLE ONLY hosts -- --- TOC entry 42 (OID 536404) +-- TOC entry 43 (OID 536404) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -446,7 +455,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 47 (OID 536920) +-- TOC entry 50 (OID 536920) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -455,7 +464,7 @@ ALTER TABLE ONLY email_notify -- --- TOC entry 48 (OID 537160) +-- TOC entry 51 (OID 537160) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -464,7 +473,7 @@ ALTER TABLE ONLY images -- --- TOC entry 49 (OID 537175) +-- TOC entry 52 (OID 537175) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -473,7 +482,7 @@ ALTER TABLE ONLY files -- --- TOC entry 43 (OID 539155) +-- TOC entry 44 (OID 539155) -- Name: pages_redirect_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -482,7 +491,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 50 (OID 540827) +-- TOC entry 53 (OID 540827) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -491,7 +500,7 @@ ALTER TABLE ONLY users -- --- TOC entry 51 (OID 540837) +-- TOC entry 54 (OID 540837) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -499,6 +508,24 @@ ALTER TABLE ONLY usercookies ADD CONSTRAINT "$1" FOREIGN KEY (userid) REFERENCES users(id); +-- +-- TOC entry 45 (OID 540942) +-- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: rich +-- + +ALTER TABLE ONLY pages + ADD CONSTRAINT "$2" FOREIGN KEY (logged_user) REFERENCES users(id); + + +-- +-- TOC entry 46 (OID 540947) +-- Name: pages_user_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich +-- + +ALTER TABLE ONLY pages + ADD CONSTRAINT pages_user_cn FOREIGN KEY (hostid, logged_user) REFERENCES users(hostid, id); + + SET SESSION AUTHORIZATION 'postgres'; -- diff --git a/html/_css/users.css b/html/_css/users.css new file mode 100644 index 0000000..0d20201 --- /dev/null +++ b/html/_css/users.css @@ -0,0 +1,4 @@ +/* Stylesheet for COCANWIKI, derived from EWM. + * $Id: users.css,v 1.1 2004/09/08 10:42:20 rich Exp $ + */ + diff --git a/html/_graphics/tick.png b/html/_graphics/tick.png new file mode 100644 index 0000000..114dee9 Binary files /dev/null and b/html/_graphics/tick.png differ diff --git a/scripts/Makefile b/scripts/Makefile index 33f24df..4fa484b 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.6 2004/09/07 17:16:46 rich Exp $ +# $Id: Makefile,v 1.7 2004/09/08 10:42:20 rich Exp $ include ../Makefile.config @@ -58,7 +58,8 @@ OBJS := create.cmo \ upload_file.cmo \ upload_file_form.cmo \ upload_image.cmo \ - upload_image_form.cmo + upload_image_form.cmo \ + users.cmo ADMIN_OBJS := \ admin/admin.cmo \ diff --git a/scripts/cocanwiki_date.ml b/scripts/cocanwiki_date.ml index 754fac4..38315f2 100644 --- a/scripts/cocanwiki_date.ml +++ b/scripts/cocanwiki_date.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki_date.ml,v 1.2 2004/09/07 14:58:34 rich Exp $ + * $Id: cocanwiki_date.ml,v 1.3 2004/09/08 10:42:20 rich Exp $ *) open Apache @@ -21,9 +21,11 @@ let short_month = function | _ -> invalid_arg "short_month" (* Generate a printable datestamp for pages. *) -let printable_date (date, _) = +let printable_date' date = sprintf "%d %s %04d" date.Dbi.day (short_month date.Dbi.month) date.Dbi.year +let printable_date (date, _) = printable_date' date + let printable_date_time (date, time) = sprintf "%d %s %04d %02d:%02d" date.Dbi.day (short_month date.Dbi.month) date.Dbi.year time.Dbi.hour time.Dbi.min diff --git a/scripts/page.ml b/scripts/page.ml index 53e6791..c34af77 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: page.ml,v 1.5 2004/09/08 09:54:28 rich Exp $ + * $Id: page.ml,v 1.6 2004/09/08 10:42:20 rich Exp $ *) open Apache @@ -39,8 +39,9 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, edit_anon) user = | [ `Bool has_host_css ] -> has_host_css | _ -> assert false in - (* Can the user edit? *) + (* Can the user edit? Manage users? *) let can_edit = can_edit edit_anon user in + let can_manage_users = can_manage_users user in (* This code generates ordinary pages. *) let make_page title description pageid last_modified_date has_page_css @@ -66,6 +67,7 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, edit_anon) user = t#conditional "has_page_css" has_page_css; t#conditional "can_edit" can_edit; + t#conditional "can_manage_users" can_manage_users; (* Pull out the sections in this page. *) let sth = dbh#prepare_cached diff --git a/scripts/users.ml b/scripts/users.ml new file mode 100644 index 0000000..8fff55c --- /dev/null +++ b/scripts/users.ml @@ -0,0 +1,46 @@ +(* COCANWIKI scripts. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: users.ml,v 1.1 2004/09/08 10:42:20 rich Exp $ + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template +open Cocanwiki_date + +let template = get_template "users.html" + +let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ = + let sth = + dbh#prepare_cached + "select id, name, email, registration_date, can_edit, can_manage_users + from users where hostid = ? order by name" in + sth#execute [`Int hostid]; + + let table = + sth#map + (function + [`Int userid; `String name; (`Null | `String _) as email; + `Date registration_date; + `Bool can_edit; `Bool can_manage_users] -> + let email = match email with `Null -> "" | `String s -> s in + [ "userid", Template.VarString (string_of_int userid); + "name", Template.VarString name; + "email", Template.VarString email; + "registration_date", + Template.VarString (printable_date' registration_date); + "can_edit", Template.VarConditional can_edit; + "can_manage_users", Template.VarConditional can_manage_users ] + | _ -> assert false) in + + template#table "users" table; + + q#template template + +let () = + register_script ~restrict:[CanManageUsers] run diff --git a/templates/page.html b/templates/page.html index 10aab87..6b64934 100644 --- a/templates/page.html +++ b/templates/page.html @@ -61,7 +61,10 @@
  • Edit stylesheet for this page |
  • Wiki administration |
  • ::end:: -
  • ::if(user_logged_in):: ::username_html:: (logout) ::else:: Create account or login ::end::
  • +
  • ::if(user_logged_in):: ::username_html:: (logout) ::else:: Create account or log in ::end:: |
  • +::if(can_manage_users):: +
  • Manage users
  • +::end::
    diff --git a/templates/users.html b/templates/users.html new file mode 100644 index 0000000..79c2d5e --- /dev/null +++ b/templates/users.html @@ -0,0 +1,59 @@ + + + +Users + + + + + +

    Users

    + + + + + + + + + + + + + + + +::table(users):: + + + + + + + +::end:: + +
    Name Email address Registration Permissions
    Can edit Can manage users
    ::name_html:: ::email_html:: ::registration_date_html:: ::if(can_edit)::Can edit::end:: ::if(can_manage_users)::Can manage users::end::
    + + + + + +
    + + + + + \ No newline at end of file