Create account, forgotten password.
authorrich <rich>
Tue, 7 Sep 2004 17:16:46 +0000 (17:16 +0000)
committerrich <rich>
Tue, 7 Sep 2004 17:16:46 +0000 (17:16 +0000)
scripts/Makefile
scripts/forgot_password.ml [new file with mode: 0644]
scripts/forgot_password_form.ml [new file with mode: 0644]
scripts/signup.ml
templates/forgot_password_form.html [new file with mode: 0644]

index c7df219..33f24df 100644 (file)
@@ -1,5 +1,5 @@
 # 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
 
@@ -33,6 +33,8 @@ OBJS := create.cmo \
        edit_page_css_form.cmo \
        file.cmo \
        files.cmo \
+       forgot_password.cmo \
+       forgot_password_form.cmo \
        history.cmo \
        hoststyle.cmo \
        image.cmo \
diff --git a/scripts/forgot_password.ml b/scripts/forgot_password.ml
new file mode 100644 (file)
index 0000000..5a77907
--- /dev/null
@@ -0,0 +1,70 @@
+(* 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
diff --git a/scripts/forgot_password_form.ml b/scripts/forgot_password_form.ml
new file mode 100644 (file)
index 0000000..700f0b8
--- /dev/null
@@ -0,0 +1,21 @@
+(* 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
index ea90b34..84c560e 100644 (file)
@@ -1,7 +1,7 @@
 (* 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
@@ -44,6 +44,11 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
 
   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
 
diff --git a/templates/forgot_password_form.html b/templates/forgot_password_form.html
new file mode 100644 (file)
index 0000000..c077f1e
--- /dev/null
@@ -0,0 +1,53 @@
+<!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&nbsp;page</a> | </li>
+<li> <a href="/_sitemap">Sitemap</a> | </li>
+<li> <a href="/_recent">Recent&nbsp;changes</a> </li>
+</ul>
+
+<ul id="bottommenu" class="menu">
+<li> <a href="/">Home&nbsp;page</a> | </li>
+<li> <a href="/_sitemap">Sitemap</a> | </li>
+<li> <a href="/_recent">Recent&nbsp;changes</a> </li>
+</ul>
+
+<hr/>
+
+<ul id="footer" class="menu">
+<li> <a href="/copyright">Copyright &copy; 2004</a> </li>
+</ul>
+
+</body>
+</html>
\ No newline at end of file