# Apache configuration for COCANWIKI.
-# $Id: cocanwiki.conf,v 1.2 2004/09/07 16:19:43 rich Exp $
+# $Id: cocanwiki.conf,v 1.3 2004/09/08 12:45:37 rich Exp $
# Uncomment the following lines if necessary. You will probably need
# to adjust the paths to reflect where cocanwiki is really installed.
RewriteRule ^/_logout$ /_bin/logout.cmo [PT,L,QSA]
RewriteRule ^/_recent$ /_bin/recent.cmo [PT,L,QSA]
RewriteRule ^/_sitemap$ /_bin/sitemap.cmo [PT,L,QSA]
+RewriteRule ^/_users$ /_bin/users.cmo [PT,L,QSA]
# Image and file downloads.
RewriteRule ^/_file/(.*)$ /_bin/file.cmo?name=$1 [PT,L,QSA]
/* Stylesheet for COCANWIKI, derived from EWM.
- * $Id: users.css,v 1.2 2004/09/08 12:02:29 rich Exp $
+ * $Id: users.css,v 1.3 2004/09/08 12:45:37 rich Exp $
*/
table#users {
table#users td {
border: 1px solid #eee;
padding: 6px;
-}
\ No newline at end of file
+}
+
+table#edit_user th {
+ vertical-align: top;
+ text-align: right;
+}
# Makefile for COCANWIKI.
-# $Id: Makefile,v 1.7 2004/09/08 10:42:20 rich Exp $
+# $Id: Makefile,v 1.8 2004/09/08 12:45:38 rich Exp $
include ../Makefile.config
edit.cmo \
edit_page_css.cmo \
edit_page_css_form.cmo \
+ edit_user.cmo \
+ edit_user_form.cmo \
file.cmo \
files.cmo \
forgot_password.cmo \
--- /dev/null
+(* COCANWIKI scripts.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: edit_user.ml,v 1.1 2004/09/08 12:45:38 rich Exp $
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_strings
+open Cocanwiki_ok
+
+let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) self =
+ let userid = int_of_string (q#param "userid") in
+
+ (* Get the user's original name. If we're going to change the
+ * name, we need to do additional checks.
+ *)
+ let sth = dbh#prepare_cached "select name from users
+ where hostid = ? and id = ?" in
+ sth#execute [`Int hostid; `Int userid];
+ let original_name = sth#fetch1string () in
+
+ let name = trim (q#param "name") in
+
+ if original_name <> name then (
+ if name = "" then (
+ error ~back_button:true ~title:"Bad username"
+ q "The username you gave is empty.";
+ raise CgiExit
+ );
+
+ (* Check it's not a duplicate, then change it. *)
+ let sth = dbh#prepare_cached "select id from users
+ where hostid = ? and name = ?" in
+ sth#execute [`Int hostid; `String name];
+
+ (try
+ sth#fetch1 ();
+ error ~back_button:true ~title:"Username already taken"
+ q ("That username has already been taken by another user.");
+ raise CgiExit
+ with
+ Not_found -> ());
+
+ let sth = dbh#prepare_cached "update users set name = ?
+ where hostid = ? and id = ?" in
+ sth#execute [`String name; `Int hostid; `Int userid]
+ );
+
+ (* Change email address and permissions. *)
+ let email = trim (q#param "email") in
+ let email = if email = "" then `Null else `String email in
+
+ let can_edit = q#param_true "can_edit" in
+ let can_manage_users = q#param_true "can_manage_users" in
+
+ (* Trying to remove manage users permission from self? *)
+ (match can_manage_users, self with
+ | false, User (id, _, _) when id = userid ->
+ error ~back_button:true ~title:"Remove manage users from self"
+ q ("You tried to remove 'Manage users' permission from yourself. "^
+ "You can't do this. You'll have to do it from another "^
+ "user account.");
+ raise CgiExit
+ | _ -> ());
+
+ let sth = dbh#prepare_cached "update users set email = ?,
+ can_edit = ?, can_manage_users = ?
+ where hostid = ? and id = ?" in
+ sth#execute [email; `Bool can_edit; `Bool can_manage_users;
+ `Int hostid; `Int userid];
+
+ (* Finish up. *)
+ dbh#commit ();
+
+ let buttons = [ ok_button "/_users" ] in
+ ok ~buttons ~title:"Saved"
+ q "Changes were saved."
+
+let () =
+ register_script ~restrict:[CanManageUsers] run
--- /dev/null
+(* COCANWIKI scripts.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: edit_user_form.ml,v 1.1 2004/09/08 12:45:38 rich Exp $
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_template
+open Cocanwiki_date
+
+let template = get_template "edit_user_form.html"
+
+let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+ let userid = int_of_string (q#param "userid") in
+
+ let sth =
+ dbh#prepare_cached
+ "select u.name, u.email, u.registration_date,
+ u.can_edit, u.can_manage_users,
+ (select count(*) from pages where logged_user = u.id),
+ (select count(*) from pages
+ where logged_user = u.id and url_deleted is null)
+ from users u where u.hostid = ? and u.id = ?" in
+ sth#execute [`Int hostid; `Int userid];
+
+ let name, email, registration_date, can_edit, can_manage_users, nr_edits,
+ nr_edits_live =
+ match sth#fetch1 () with
+ [`String name; (`Null | `String _) as email;
+ `Date registration_date;
+ `Bool can_edit; `Bool can_manage_users;
+ `Int nr_edits; `Int nr_edits_live] ->
+ name, email, registration_date, can_edit, can_manage_users,
+ nr_edits, nr_edits_live
+ | _ -> assert false in
+
+ template#set "userid" (string_of_int userid);
+ template#set "name" name;
+ template#set "email" (match email with `Null -> "" | `String s -> s);
+ template#set "registration_date" (printable_date' registration_date);
+ template#conditional "can_edit" can_edit;
+ template#conditional "can_manage_users" can_manage_users;
+ template#set "nr_edits" (string_of_int nr_edits);
+ template#set "nr_edits_live" (string_of_int nr_edits_live);
+
+ q#template template
+
+let () =
+ register_script ~restrict:[CanManageUsers] run
(* COCANWIKI scripts.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: signup.ml,v 1.2 2004/09/07 17:16:46 rich Exp $
+ * $Id: signup.ml,v 1.3 2004/09/08 12:45:38 rich Exp $
*)
open Apache
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 name = ?" in
- sth#execute [`String username];
+ let sth = dbh#prepare_cached "select id from users
+ where hostid = ? and name = ?" in
+ sth#execute [`Int hostid; `String username];
(try
sth#fetch1 ();
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>User: ::name_html::</title>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="/_css/standard.css" type="text/css" title="Standard"/>
+<link rel="stylesheet" href="/_css/users.css" type="text/css" title="Standard"/>
+</head><body>
+
+<h1>User: ::name_html::</h1>
+
+<ul class="menu">
+<li> <a href="/_users">Users</a> | </li>
+<li> <a href="/_bin/set_password_form.cmo?userid=::userid::">Set a password for this user</a> | </li>
+<li> <a href="/_bin/delete_user_form.cmo?userid=::userid::">Delete this user</a> </li>
+</ul>
+
+<form method="post" action="/_bin/edit_user.cmo">
+<input type="hidden" name="userid" value="::userid::"/>
+
+<table id="edit_user">
+
+<tr>
+<th> Username: </th>
+<td> <input name="name" value="::name_html_tag::" size="32" maxlength="32"/> </td>
+</tr>
+<tr>
+<th> Email: </th>
+<td> <input name="email" value="::email_html_tag::" size="40"/> </td>
+</tr>
+<tr>
+<th> Permissions: </th>
+<td>
+<input id="can_edit" type="checkbox" name="can_edit" value="1" ::if(can_edit)::checked="checked"::end::/><label for="can_edit">Edit</label>
+<br/>
+<input id="can_manage_users" type="checkbox" name="can_manage_users" value="1" ::if(can_manage_users)::checked="checked"::end::/><label for="can_manage_users">Manage users</label>
+</td>
+</tr>
+<tr>
+<td></td>
+<td> <input type="submit" value=" Save changes " /> </td>
+</tr>
+
+</table>
+
+</form>
+
+<ul id="topmenu" class="menu">
+<li> <a href="/">Home page</a> | </li>
+<li> <a href="/_sitemap">Sitemap</a> | </li>
+<li> <a href="/_recent">Recent changes</a> </li>
+</ul>
+
+<ul id="bottommenu" class="menu">
+<li> <a href="/">Home page</a> | </li>
+<li> <a href="/_sitemap">Sitemap</a> | </li>
+<li> <a href="/_recent">Recent changes</a> </li>
+</ul>
+
+<hr/>
+
+<ul id="footer" class="menu">
+<li> <a href="/copyright">Copyright © 2004</a> </li>
+</ul>
+
+</body>
+</html>
\ No newline at end of file
::end::
<li> ::if(user_logged_in):: ::username_html:: <a href="/_logout">(logout)</a> ::else:: <a href="/_login">Create account or log in</a> ::end:: | </li>
::if(can_manage_users)::
-<li> <a href="/_bin/users.cmo">Manage users</a> </li>
+<li> <a href="/_users">Manage users</a> </li>
::end::
</ul>
<table id="users">
<tr>
-<th rowspan="2"> Name </th>
+<th rowspan="2"> Username </th>
<th rowspan="2"> Email address </th>
<th rowspan="2"> Registration </th>
<th colspan="2"> Permissions </th>