# Makefile for COCANWIKI.
-# $Id: Makefile,v 1.5 2004/09/07 16:58:03 rich Exp $
+# $Id: Makefile,v 1.6 2004/09/07 17:16:46 rich Exp $
include ../Makefile.config
edit_page_css_form.cmo \
file.cmo \
files.cmo \
+ forgot_password.cmo \
+ forgot_password_form.cmo \
history.cmo \
hoststyle.cmo \
image.cmo \
--- /dev/null
+(* COCANWIKI scripts.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: forgot_password.ml,v 1.1 2004/09/07 17:16:46 rich Exp $
+ *)
+
+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, hostname, _) _ =
+ let name = trim (q#param "name") in
+
+ if name = "" then (
+ error ~back_button:true ~title:"No username or email address"
+ q "You didn't give a username or email address";
+ raise CgiExit
+ );
+
+ (* Look it up in the database. *)
+ let sth = dbh#prepare_cached "select email, name, password from users
+ where hostid = ?
+ and (lower (name) = lower (?)
+ or lower (email) = lower (?))" in
+ sth#execute [`Int hostid; `String name; `String name];
+
+ try
+ let email, name, password = match sth#fetch1 () with
+ [ `String email; `String name; `String password ] ->
+ email, name, password
+ | _ -> assert false in
+
+ (* Get the IP address of the user, if available. *)
+ let ip =
+ try Connection.remote_ip (Request.connection r) with Not_found -> "" in
+
+ let subject = "Password for " ^ hostname in
+
+ let body =
+ "Someone, possibly you, requested your password for " ^ hostname ^
+ ".\n" ^
+ "Username: " ^ name ^ "\n" ^
+ "Password: " ^ password ^ "\n" ^
+ "\n" ^
+ "IP address of request: " ^ ip ^ "\n" in
+
+ Sendmail.send_mail ~subject ~to_addr:[ email ] ~body ();
+
+ let buttons = [ ok_button "/_login" ] in
+ ok ~buttons ~title:"Password sent by email"
+ q
+ ("Your password was sent by email. If you don't receive the password " ^
+ "within an hour, please notify the site's administrator.")
+ with
+ Not_found ->
+ (* Artificially limit the rate at which people can search the database
+ * for usernames.
+ *)
+ Unix.sleep 10;
+
+ error ~back_button:true ~title:"Nothing known"
+ q "Sorry, don't know anyone with that name or email address."
+
+let () =
+ register_script run
--- /dev/null
+(* COCANWIKI scripts.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: forgot_password_form.ml,v 1.1 2004/09/07 17:16:46 rich Exp $
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_template
+
+let template = get_template "forgot_password_form.html"
+
+let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+ q#template template
+
+let () =
+ register_script run
(* COCANWIKI scripts.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: signup.ml,v 1.1 2004/09/07 16:58:03 rich Exp $
+ * $Id: signup.ml,v 1.2 2004/09/07 17:16:46 rich Exp $
*)
open Apache
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
--- /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>Forgotten your password?</title>
+<meta name="description" content="Log in to this site for extra features." />
+<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/login.css" type="text/css" title="Standard"/>
+</head><body>
+
+<h1>Forgotten your password?</h1>
+
+<p>
+Type in your username or your email address. If we have a matching
+username or email address on record, we will email you your password.
+</p>
+
+<form method="post" action="/_bin/forgot_password.cmo">
+<table class="create">
+
+<tr>
+<th> Username or email address: </th>
+<td> <input name="name" value="" size="32" /> </td>
+</tr>
+
+<tr>
+<th></th>
+<td> <input type="submit" value="Send me my password" /> </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