image.cmx: cgi_expires.cmx cocanwiki.cmx
images.cmo: cocanwiki.cmo cocanwiki_template.cmo
images.cmx: cocanwiki.cmx cocanwiki_template.cmx
+login.cmo: cocanwiki.cmo cocanwiki_ok.cmo
+login.cmx: cocanwiki.cmx cocanwiki_ok.cmx
+login_form.cmo: cocanwiki.cmo cocanwiki_strings.cmo cocanwiki_template.cmo
+login_form.cmx: cocanwiki.cmx cocanwiki_strings.cmx cocanwiki_template.cmx
+logout.cmo: cocanwiki.cmo cocanwiki_ok.cmo
+logout.cmx: cocanwiki.cmx cocanwiki_ok.cmx
page.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_ok.cmo \
- cocanwiki_template.cmo wikilib.cmi
+ cocanwiki_template.cmo cocanwiki_version.cmo wikilib.cmi
page.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_ok.cmx \
- cocanwiki_template.cmx wikilib.cmx
+ cocanwiki_template.cmx cocanwiki_version.cmx wikilib.cmx
pagestyle.cmo: cgi_expires.cmo cocanwiki.cmo
pagestyle.cmx: cgi_expires.cmx cocanwiki.cmx
preview.cmo: cocanwiki.cmo wikilib.cmi
cocanwiki_template.cmx
search.cmo: cocanwiki.cmo
search.cmx: cocanwiki.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 \
cocanwiki_template.cmo wikilib.cmi
sitemap.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_strings.cmx \
--- /dev/null
+(* 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 $
+ *)
+
+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, _, _) _ =
+ (* Verify that we're allowed to create accounts anonymously
+ * on this host.
+ *)
+ let sth = dbh#prepare_cached "select create_account_anon from hosts
+ where id = ?" in
+ sth#execute [`Int hostid];
+
+ let create_account_anon =
+ match sth#fetch1 () with
+ [ `Bool true ] -> ()
+ | _ -> assert false in
+
+ 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
+
+ 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 name = ?" in
+ sth#execute [`String username];
+
+ (try
+ sth#fetch1 ();
+ error ~back_button:true ~title:"Username already taken"
+ q ("Someone, possibly you, has already taken that username. " ^
+ "If you think you have forgotten your password, try going back " ^
+ "and clicking on the 'Forgotten your password?' link.");
+ raise CgiExit
+ with
+ Not_found -> ());
+
+ (* Create the user account. *)
+ let sth = dbh#prepare_cached "insert into users (name, password, email,
+ hostid)
+ values (?, ?, ?, ?)" in
+ sth#execute [`String username; `String password; email; `Int hostid];
+
+ let userid = sth#serial "users_id_seq" in
+
+ (* Create a cookie. *)
+ let cookie = random_sessionid () in
+ let sth = dbh#prepare_cached "insert into usercookies (userid, cookie)
+ values (?, ?)" in
+ sth#execute [`Int userid; `String cookie];
+
+ dbh#commit ();
+
+ let buttons = [ ok_button "/" ] in
+ let cookie = Cookie.cookie ~name:"auth" ~value:cookie ~path:"/" () in
+
+ ok ~title:"Account created"
+ ~buttons
+ ~cookie
+ q ("An account was created for you, " ^ username ^ ". " ^
+ "We hope you enjoy using this service.")
+
+let () =
+ register_script run
::if(create_account_anon)::
-<form method="post" action="/_bin/create_account.cmo">
+<form method="post" action="/_bin/signup.cmo">
<table class="create">
<tr>
<tr>
<th> Password: </th>
-<td> <input type="password" name="password" value="" size="32" maxlength="32"/> </td>
+<td> <input type="password" name="password1" value="" size="32" maxlength="32"/> </td>
</tr>
<tr>
<th> Password again: </th>
-<td> <input type="password" name="password" value="" size="32" maxlength="32"/> </td>
+<td> <input type="password" name="password2" value="" size="32" maxlength="32"/> </td>
</tr>
<tr>