From 867889b6d04b6381c74974e338672ee02d61920e Mon Sep 17 00:00:00 2001 From: rich Date: Tue, 21 Sep 2004 13:01:15 +0000 Subject: [PATCH] Completed all user scripts. Username now shown in recent/history pages when a user makes an edit logged in. --- MANIFEST | 9 ++++ scripts/.depend | 12 ++++++ scripts/Makefile | 8 +++- scripts/create.ml | 15 ++++--- scripts/create_user.ml | 92 ++++++++++++++++++++++++++++++++++++++++ scripts/create_user_form.ml | 36 ++++++++++++++++ scripts/delete_user.ml | 75 ++++++++++++++++++++++++++++++++ scripts/delete_user_form.ml | 65 ++++++++++++++++++++++++++++ scripts/edit.ml | 15 ++++--- scripts/edit_page_css.ml | 15 ++++--- scripts/history.ml | 29 ++++++++++--- scripts/recent.ml | 31 ++++++++++---- scripts/restore.ml | 15 ++++--- scripts/set_password.ml | 53 +++++++++++++++++++++++ scripts/set_password_form.ml | 47 ++++++++++++++++++++ templates/create_user_form.html | 80 ++++++++++++++++++++++++++++++++++ templates/delete_user_form.html | 59 ++++++++++++++++++++++++++ templates/history.html | 2 + templates/recent.html | 2 + templates/set_password_form.html | 65 ++++++++++++++++++++++++++++ 20 files changed, 689 insertions(+), 36 deletions(-) create mode 100644 scripts/create_user.ml create mode 100644 scripts/create_user_form.ml create mode 100644 scripts/delete_user.ml create mode 100644 scripts/delete_user_form.ml create mode 100644 scripts/set_password.ml create mode 100644 scripts/set_password_form.ml create mode 100644 templates/create_user_form.html create mode 100644 templates/delete_user_form.html create mode 100644 templates/set_password_form.html diff --git a/MANIFEST b/MANIFEST index f0371c8..40ae0ba 100644 --- a/MANIFEST +++ b/MANIFEST @@ -66,10 +66,14 @@ scripts/contact_show.ml scripts/contacts.ml scripts/create.ml scripts/create_form.ml +scripts/create_user.ml +scripts/create_user_form.ml scripts/delete_file.ml scripts/delete_file_form.ml scripts/delete_image.ml scripts/delete_image_form.ml +scripts/delete_user.ml +scripts/delete_user_form.ml scripts/diff.ml scripts/edit.ml scripts/edit_page_css.ml @@ -98,6 +102,8 @@ scripts/rss.ml scripts/search.ml scripts/send_feedback.ml scripts/send_feedback_form.ml +scripts/set_password.ml +scripts/set_password_form.ml scripts/signup.ml scripts/sitemap.ml scripts/undelete_file.ml @@ -122,8 +128,10 @@ templates/contact.txt templates/contact_show.html templates/contacts.html templates/create_form.html +templates/create_user_form.html templates/delete_file_form.html templates/delete_image_form.html +templates/delete_user_form.html templates/diff.html templates/edit.html templates/edit_conflict.html @@ -143,6 +151,7 @@ templates/restore_form.html templates/rss.xml templates/send_feedback.txt templates/send_feedback_form.html +templates/set_password_form.html templates/sitemap.html templates/undelete_file_form.html templates/undelete_image_form.html diff --git a/scripts/.depend b/scripts/.depend index b29a791..a93277e 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -30,6 +30,10 @@ create_form.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi \ wikilib.cmi create_form.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx \ wikilib.cmx +create_user.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo +create_user.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx +create_user_form.cmo: cocanwiki.cmo cocanwiki_template.cmi +create_user_form.cmx: cocanwiki.cmx cocanwiki_template.cmx delete_file.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo cocanwiki_ok.cmo delete_file.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx cocanwiki_ok.cmx delete_file_form.cmo: cocanwiki.cmo cocanwiki_template.cmi @@ -38,6 +42,10 @@ delete_image.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo cocanwiki_ok.cmo delete_image.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx cocanwiki_ok.cmx delete_image_form.cmo: cocanwiki.cmo cocanwiki_template.cmi delete_image_form.cmx: cocanwiki.cmx cocanwiki_template.cmx +delete_user.cmo: cocanwiki.cmo cocanwiki_ok.cmo +delete_user.cmx: cocanwiki.cmx cocanwiki_ok.cmx +delete_user_form.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi +delete_user_form.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx diff.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_template.cmi diff.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_template.cmx edit.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_emailnotify.cmo \ @@ -106,6 +114,10 @@ send_feedback.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi send_feedback.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx send_feedback_form.cmo: cocanwiki.cmo cocanwiki_template.cmi send_feedback_form.cmx: cocanwiki.cmx cocanwiki_template.cmx +set_password.cmo: cocanwiki.cmo cocanwiki_ok.cmo +set_password.cmx: cocanwiki.cmx cocanwiki_ok.cmx +set_password_form.cmo: cocanwiki.cmo cocanwiki_template.cmi +set_password_form.cmx: cocanwiki.cmx cocanwiki_template.cmx signup.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo signup.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx sitemap.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_strings.cmo \ diff --git a/scripts/Makefile b/scripts/Makefile index a5ca44a..de06781 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.14 2004/09/20 17:18:26 rich Exp $ +# $Id: Makefile,v 1.15 2004/09/21 13:01:15 rich Exp $ include ../Makefile.config @@ -27,10 +27,14 @@ OBJS := 00-TEMPLATE.cmo \ contacts.cmo \ create.cmo \ create_form.cmo \ + create_user.cmo \ + create_user_form.cmo \ delete_file.cmo \ delete_file_form.cmo \ delete_image.cmo \ delete_image_form.cmo \ + delete_user.cmo \ + delete_user_form.cmo \ diff.cmo \ edit.cmo \ edit_page_css.cmo \ @@ -59,6 +63,8 @@ OBJS := 00-TEMPLATE.cmo \ search.cmo \ send_feedback.cmo \ send_feedback_form.cmo \ + set_password.cmo \ + set_password_form.cmo \ signup.cmo \ sitemap.cmo \ undelete_file.cmo \ diff --git a/scripts/create.ml b/scripts/create.ml index a1d1d72..9478190 100644 --- a/scripts/create.ml +++ b/scripts/create.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: create.ml,v 1.6 2004/09/20 10:56:47 rich Exp $ + * $Id: create.ml,v 1.7 2004/09/21 13:01: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 @@ -30,7 +30,7 @@ open Cocanwiki open Cocanwiki_emailnotify open Cocanwiki_ok -let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = +let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user = (* Get the page title. *) let title = q#param "title" in @@ -59,12 +59,17 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = try `String (Connection.remote_ip (Request.connection r)) with Not_found -> `Null in + let logged_user = + match user with + | User (id, _, _) -> `Int id + | _ -> `Null in + (* Create the page. *) let sth = dbh#prepare_cached "insert into pages (hostid, url, title, - description, logged_ip) - values (?, ?, ?, ?, ?)" in + description, logged_ip, logged_user) + values (?, ?, ?, ?, ?, ?)" in sth#execute [`Int hostid; `String url; `String title; `String description; - logged_ip]; + logged_ip; logged_user]; let pageid = sth#serial "pages_id_seq" in diff --git a/scripts/create_user.ml b/scripts/create_user.ml new file mode 100644 index 0000000..dc72b3b --- /dev/null +++ b/scripts/create_user.ml @@ -0,0 +1,92 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: create_user.ml,v 1.1 2004/09/21 13:01: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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_ok +open Cocanwiki_strings + +let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = + let username = trim (q#param "username") in + let password1 = trim (q#param "password1") in + let password2 = trim (q#param "password2") in + + if username = "" || password1 = "" || password2 = "" then ( + error ~back_button:true ~title:"Bad username or password" + q "The username or password you gave is empty."; + raise CgiExit + ); + + if password1 <> password2 then ( + error ~back_button:true ~title:"Passwords don't match" + q "The two passwords you gave aren't identical."; + raise CgiExit + ); + + let password = password1 in + + (* + Uh oh ... Not making UNICODE assumptions ... XXX + if String.length username > 32 || String.length password > 32 then + *) + + let email = trim (q#param "email") in + let email = if string_is_whitespace email then `Null else `String email in + + (* Not a duplicate? *) + let sth = dbh#prepare_cached "select id from users + where hostid = ? and name = ?" in + sth#execute [`Int hostid; `String username]; + + (try + sth#fetch1 (); + error ~back_button:true ~title:"Username already taken" + q "Someone has already taken that username."; + raise CgiExit + with + Not_found -> ()); + + let can_edit = q#param_true "can_edit" in + let can_manage_users = q#param_true "can_manage_users" in + let can_manage_contacts = q#param_true "can_manage_contacts" in + + (* Create the user account. *) + let sth = dbh#prepare_cached "insert into users (name, password, email, + hostid, can_edit, can_manage_users, + can_manage_contacts) + values (?, ?, ?, ?, ?, ?, ?)" in + sth#execute [`String username; `String password; email; `Int hostid; + `Bool can_edit; `Bool can_manage_users; + `Bool can_manage_contacts]; + + dbh#commit (); + + let buttons = [ ok_button "/_users" ] in + + ok ~title:"Account created" ~buttons + q ("An account was created for " ^ username ^ ".") + +let () = + register_script ~restrict:[CanManageUsers] run diff --git a/scripts/create_user_form.ml b/scripts/create_user_form.ml new file mode 100644 index 0000000..f3bf33e --- /dev/null +++ b/scripts/create_user_form.ml @@ -0,0 +1,36 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: create_user_form.ml,v 1.1 2004/09/21 13:01: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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template + +let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = + let template = get_template dbh hostid "create_user_form.html" in + + q#template template + +let () = + register_script ~restrict:[CanManageUsers] run diff --git a/scripts/delete_user.ml b/scripts/delete_user.ml new file mode 100644 index 0000000..782c6b0 --- /dev/null +++ b/scripts/delete_user.ml @@ -0,0 +1,75 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: delete_user.ml,v 1.1 2004/09/21 13:01: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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_ok + +let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} self = + if q#param_true "cancel" then ( + (* Request cancelled. *) + q#redirect ("http://" ^ hostname ^ "/_users"); + raise CgiExit + ); + + let userid = int_of_string (q#param "userid") in + + (* Check userid belongs to host. The statements below wouldn't + * enforce this correctly ... + *) + let sth = + dbh#prepare_cached "select 1 from users where id = ? and hostid = ?" in + sth#execute [`Int userid; `Int hostid]; + + assert (sth#fetch1int () = 1); + + (* Can't delete self! *) + let () = + match self with + | User (id, _, _) when id = userid -> + error ~back_button:true ~title:"Delete own account" + q "You cannot delete your own user account."; + raise CgiExit + | _ -> () in + + (* Delete the user. *) + let sth = dbh#prepare_cached "delete from usercookies where userid = ?" in + sth#execute [`Int userid]; + + let sth = dbh#prepare_cached "update pages set logged_user = null + where logged_user = ? and hostid = ?" in + sth#execute [`Int userid; `Int hostid]; + + let sth = + dbh#prepare_cached "delete from users where id = ? and hostid = ?" in + sth#execute [`Int userid; `Int hostid]; + + dbh#commit (); + + ok ~title:"Account deleted" ~buttons:[ok_button "/_users"] + q "That user account was deleted." + +let () = + register_script ~restrict:[CanManageUsers] run diff --git a/scripts/delete_user_form.ml b/scripts/delete_user_form.ml new file mode 100644 index 0000000..f982f1e --- /dev/null +++ b/scripts/delete_user_form.ml @@ -0,0 +1,65 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: delete_user_form.ml,v 1.1 2004/09/21 13:01: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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template +open Cocanwiki_ok + +let run r (q : cgi) (dbh : Dbi.connection) hostid _ self = + let template = get_template dbh hostid "delete_user_form.html" in + + let userid = int_of_string (q#param "userid") in + template#set "userid" (string_of_int userid); + + (* Can't delete self! *) + let () = + match self with + | User (id, _, _) when id = userid -> + error ~back_button:true ~title:"Delete own account" + q "You cannot delete your own user account."; + raise CgiExit + | _ -> () in + + (* Get this user from the database. *) + let sth = dbh#prepare_cached "select name, email from users + where id = ? and hostid = ?" in + sth#execute [`Int userid; `Int hostid]; + + let username, email = + match sth#fetch1 () with + [ `String username; `String email ] -> + username, email + | [ `String username; `Null ] -> + username, "" + | _ -> assert false in + + template#set "username" username; + template#set "email" email; + + q#template template + +let () = + register_script ~restrict:[CanManageUsers] run diff --git a/scripts/edit.ml b/scripts/edit.ml index bf7b482..00d48ab 100644 --- a/scripts/edit.ml +++ b/scripts/edit.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit.ml,v 1.9 2004/09/20 10:56:47 rich Exp $ + * $Id: edit.ml,v 1.10 2004/09/21 13:01: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 @@ -45,7 +45,7 @@ type model_t = { * for each section. *) } -let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = +let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user = let template = get_template dbh hostid "edit.html" in let template_conflict = get_template dbh hostid "edit_conflict.html" in @@ -409,6 +409,11 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = try `String (Connection.remote_ip (Request.connection r)) with Not_found -> `Null in + let logged_user = + match user with + | User (id, _, _) -> `Int id + | _ -> `Null in + (* Get redirect. *) let redirect = if model.redirect = "" then `Null else `String model.redirect in @@ -416,11 +421,11 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = (* Create the new page. *) let sth = dbh#prepare_cached "insert into pages (hostid, url, title, description, creation_date, logged_ip, - redirect, css) - values (?, ?, ?, ?, ?, ?, ?, ?)" in + logged_user, redirect, css) + values (?, ?, ?, ?, ?, ?, ?, ?, ?)" in sth#execute [`Int hostid; `String url; `String title; `String model.description; creation_date; logged_ip; - redirect; css]; + logged_user; redirect; css]; (* New page ID <> old page ID model.id. *) let pageid = sth#serial "pages_id_seq" in diff --git a/scripts/edit_page_css.ml b/scripts/edit_page_css.ml index a37ec89..126c289 100644 --- a/scripts/edit_page_css.ml +++ b/scripts/edit_page_css.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit_page_css.ml,v 1.7 2004/09/09 12:21:22 rich Exp $ + * $Id: edit_page_css.ml,v 1.8 2004/09/21 13:01: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 @@ -30,7 +30,7 @@ open Cocanwiki_diff open Cocanwiki_emailnotify open Cocanwiki_strings -let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = +let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user = let page = q#param "page" in let css = q#param "css" in @@ -41,6 +41,11 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = try `String (Connection.remote_ip (Request.connection r)) with Not_found -> `Null in + let logged_user = + match user with + | User (id, _, _) -> `Int id + | _ -> `Null in + (* Changing the CSS creates a new version of the page. This enables * us to revert changes to the CSS easily. *) @@ -67,10 +72,10 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = let sth = dbh#prepare_cached "insert into pages (hostid, url, title, description, creation_date, logged_ip, - redirect, css) - values (?, ?, ?, ?, ?, ?, ?, ?)" in + logged_user, redirect, css) + values (?, ?, ?, ?, ?, ?, ?, ?, ?)" in sth#execute [`Int hostid; `String page; title; description; - creation_date; logged_ip; redirect; css ]; + creation_date; logged_ip; logged_user; redirect; css ]; let pageid = sth#serial "pages_id_seq" in diff --git a/scripts/history.ml b/scripts/history.ml index 0acd164..556a6ad 100644 --- a/scripts/history.ml +++ b/scripts/history.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: history.ml,v 1.7 2004/09/09 12:21:22 rich Exp $ + * $Id: history.ml,v 1.8 2004/09/21 13:01:16 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 @@ -36,44 +36,59 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = let sth = dbh#prepare_cached - "select id, url, url_deleted, title, last_modified_date, logged_ip - from pages - where hostid = ? and (url = ? or url_deleted = ?) - order by last_modified_date desc" in + "select p.id, p.url, p.url_deleted, p.title, p.last_modified_date, + p.logged_ip, u.name + from pages p left outer join users u on p.logged_user = u.id + where p.hostid = ? and (p.url = ? or p.url_deleted = ?) + order by p.last_modified_date desc" in sth#execute [`Int hostid; `String page; `String page]; let table = sth#map (function | [`Int version; `String url; _; `String title; - `Timestamp last_modified_date; logged_ip ] -> + `Timestamp last_modified_date; logged_ip; logged_user ] -> let date = printable_date_time last_modified_date in let has_logged_ip, logged_ip = match logged_ip with `Null -> false, "" | `String ip -> true, ip | _ -> assert false in + let has_logged_user, logged_user = + match logged_user with + `Null -> false, "" + | `String name -> true, name + | _ -> assert false in [ "version", Template.VarString (string_of_int version); "url", Template.VarString url; "title", Template.VarString title; "last_modified_date", Template.VarString date; "has_logged_ip", Template.VarConditional has_logged_ip; "logged_ip", Template.VarString logged_ip; + "has_logged_user", Template.VarConditional has_logged_user; + "logged_user", Template.VarString logged_user; "is_live", Template.VarConditional true ] | [`Int version; `Null; `String url; `String title; - `Timestamp last_modified_date; logged_ip ] -> + `Timestamp last_modified_date; logged_ip; logged_user ] -> let date = printable_date_time last_modified_date in let has_logged_ip, logged_ip = match logged_ip with `Null -> false, "" | `String ip -> true, ip | _ -> assert false in + let has_logged_user, logged_user = + match logged_user with + `Null -> false, "" + | `String name -> true, name + | _ -> assert false in [ "version", Template.VarString (string_of_int version); "url", Template.VarString url; "title", Template.VarString title; "last_modified_date", Template.VarString date; "has_logged_ip", Template.VarConditional has_logged_ip; "logged_ip", Template.VarString logged_ip; + "has_logged_user", Template.VarConditional has_logged_user; + "logged_user", Template.VarString logged_user; "is_live", Template.VarConditional false ] | _ -> assert false) in diff --git a/scripts/recent.ml b/scripts/recent.ml index 91575e0..997462a 100644 --- a/scripts/recent.ml +++ b/scripts/recent.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: recent.ml,v 1.7 2004/09/09 12:21:22 rich Exp $ + * $Id: recent.ml,v 1.8 2004/09/21 13:01:16 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 @@ -35,45 +35,60 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = let sth = dbh#prepare_cached - "select id, url, url_deleted, title, last_modified_date, logged_ip - from pages - where hostid = ? - and last_modified_date >= current_timestamp - interval ? - order by last_modified_date desc" in + "select p.id, p.url, p.url_deleted, p.title, p.last_modified_date, + p.logged_ip, u.name + from pages p left outer join users u on p.logged_user = u.id + where p.hostid = ? + and p.last_modified_date >= current_timestamp - interval ? + order by p.last_modified_date desc" in sth#execute [`Int hostid; `String max_age]; let table = sth#map (function | [`Int version; `String url; _; `String title; - `Timestamp last_modified_date; logged_ip] -> + `Timestamp last_modified_date; logged_ip; logged_user] -> let date = printable_date_time last_modified_date in let has_logged_ip, logged_ip = match logged_ip with `Null -> false, "" | `String ip -> true, ip | _ -> assert false in + let has_logged_user, logged_user = + match logged_user with + `Null -> false, "" + | `String name -> true, name + | _ -> assert false in [ "version", Template.VarString (string_of_int version); "url", Template.VarString url; "title", Template.VarString title; "last_modified_date", Template.VarString date; "has_logged_ip", Template.VarConditional has_logged_ip; "logged_ip", Template.VarString logged_ip; + "has_logged_user", Template.VarConditional has_logged_user; + "logged_user", Template.VarString logged_user; "is_live", Template.VarConditional true ] | [`Int version; `Null; `String url; `String title; - `Timestamp last_modified_date; logged_ip] -> + `Timestamp last_modified_date; logged_ip; logged_user] -> let date = printable_date_time last_modified_date in let has_logged_ip, logged_ip = match logged_ip with `Null -> false, "" | `String ip -> true, ip | _ -> assert false in + let has_logged_user, logged_user = + match logged_user with + `Null -> false, "" + | `String name -> true, name + | _ -> assert false in [ "version", Template.VarString (string_of_int version); "url", Template.VarString url; "title", Template.VarString title; "last_modified_date", Template.VarString date; "has_logged_ip", Template.VarConditional has_logged_ip; "logged_ip", Template.VarString logged_ip; + "has_logged_user", Template.VarConditional has_logged_user; + "logged_user", Template.VarString logged_user; "is_live", Template.VarConditional false ] | _ -> assert false) in diff --git a/scripts/restore.ml b/scripts/restore.ml index 167ac9e..53fb478 100644 --- a/scripts/restore.ml +++ b/scripts/restore.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: restore.ml,v 1.7 2004/09/09 12:21:22 rich Exp $ + * $Id: restore.ml,v 1.8 2004/09/21 13:01:16 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 @@ -29,7 +29,7 @@ open Cocanwiki_ok open Cocanwiki_diff open Cocanwiki_emailnotify -let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = +let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user = let version = int_of_string (q#param "version") in let page = q#param "page" in @@ -39,6 +39,11 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = try `String (Connection.remote_ip (Request.connection r)) with Not_found -> `Null in + let logged_user = + match user with + | User (id, _, _) -> `Int id + | _ -> `Null in + (* Copy the old version of the page to be live. *) let sth = dbh#prepare_cached "select title, description, creation_date, redirect, css @@ -65,10 +70,10 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = let sth = dbh#prepare_cached "insert into pages (hostid, url, title, description, creation_date, logged_ip, - redirect, css) - values (?, ?, ?, ?, ?, ?, ?, ?)" in + logged_user, redirect, css) + values (?, ?, ?, ?, ?, ?, ?, ?, ?)" in sth#execute [`Int hostid; `String page; title; description; - creation_date; logged_ip; redirect; css ]; + creation_date; logged_ip; logged_user; redirect; css ]; let pageid = sth#serial "pages_id_seq" in diff --git a/scripts/set_password.ml b/scripts/set_password.ml new file mode 100644 index 0000000..5dfbf29 --- /dev/null +++ b/scripts/set_password.ml @@ -0,0 +1,53 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: set_password.ml,v 1.1 2004/09/21 13:01:16 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_ok + +let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = + let userid = int_of_string (q#param "userid") in + let password1 = q#param "password1" in + let password2 = q#param "password2" in + + if password1 <> password2 then ( + error ~back_button:true ~title:"Passwords don't match" + q "The two passwords you gave aren't identical."; + raise CgiExit + ); + + let password = password1 in + + let sth = dbh#prepare_cached "update users set password = ? + where id = ? and hostid = ?" in + sth#execute [`String password; `Int userid; `Int hostid]; + + dbh#commit (); + + ok ~title:"Password updated" ~buttons:[ok_button "/_users"] + q "The password on that user account was updated." + +let () = + register_script ~restrict:[CanManageUsers] run diff --git a/scripts/set_password_form.ml b/scripts/set_password_form.ml new file mode 100644 index 0000000..5f884b8 --- /dev/null +++ b/scripts/set_password_form.ml @@ -0,0 +1,47 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: set_password_form.ml,v 1.1 2004/09/21 13:01:16 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template + +let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = + let template = get_template dbh hostid "set_password_form.html" in + + let userid = int_of_string (q#param "userid") in + + let sth = dbh#prepare_cached "select name from users + where id = ? and hostid = ?" in + sth#execute [`Int userid; `Int hostid]; + + let username = sth#fetch1string () in + + template#set "userid" (string_of_int userid); + template#set "username" username; + + q#template template + +let () = + register_script ~restrict:[CanManageUsers] run diff --git a/templates/create_user_form.html b/templates/create_user_form.html new file mode 100644 index 0000000..5dc64fa --- /dev/null +++ b/templates/create_user_form.html @@ -0,0 +1,80 @@ + + + +Create a user account + + + + + + +

Create a user account

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Username:
Password:
Password again:
Email:
Permissions: + + +
+ +
+ +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/templates/delete_user_form.html b/templates/delete_user_form.html new file mode 100644 index 0000000..aaab87a --- /dev/null +++ b/templates/delete_user_form.html @@ -0,0 +1,59 @@ + + + +Delete user: ::username_html:: + + + + + + +

Delete user: ::username_html::

+ +

+Are you sure you want to delete this user? +

+ + + + + + + + + + +
Username: ::username_html::
Email: ::email_html::
+ +
+ + + +
+ + + + + + + + + \ No newline at end of file diff --git a/templates/history.html b/templates/history.html index b8c8ca3..b41e5e9 100644 --- a/templates/history.html +++ b/templates/history.html @@ -15,7 +15,9 @@ ::last_modified_date_html:: (diff) ::if(is_live)::::title_html:: (live)::else::::title_html::::end:: +::if(has_logged_user)::(by ::logged_user_html::)::else:: ::if(has_logged_ip)::(from ::logged_ip_html::)::end:: +::end:: ::end:: diff --git a/templates/recent.html b/templates/recent.html index 1fbfe01..34e4325 100644 --- a/templates/recent.html +++ b/templates/recent.html @@ -16,7 +16,9 @@ (diff) (history) ::if(is_live)::::title_html:: (live)::else::::title_html::::end:: +::if(has_logged_user)::(by ::logged_user_html::)::else:: ::if(has_logged_ip)::(from ::logged_ip_html::)::end:: +::end:: ::end:: diff --git a/templates/set_password_form.html b/templates/set_password_form.html new file mode 100644 index 0000000..ba8ae9f --- /dev/null +++ b/templates/set_password_form.html @@ -0,0 +1,65 @@ + + + +Set password for this user + + + + + + +

Set password for this user

+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Username: ::username_html::
Password:
Password again:
+
+ + + + + + + + + \ No newline at end of file -- 1.8.3.1