From d13b33f240b646404de221c14387b8795a7aace9 Mon Sep 17 00:00:00 2001 From: rich Date: Tue, 7 Sep 2004 16:58:03 +0000 Subject: [PATCH] Signup for an account. --- scripts/.depend | 12 +++++-- scripts/Makefile | 3 +- scripts/signup.ml | 90 +++++++++++++++++++++++++++++++++++++++++++++++ templates/login_form.html | 6 ++-- 4 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 scripts/signup.ml diff --git a/scripts/.depend b/scripts/.depend index 037b575..d4de9ba 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -52,10 +52,16 @@ image.cmo: cgi_expires.cmo cocanwiki.cmo 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 @@ -72,6 +78,8 @@ restore_form.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_ok.cmx \ 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 \ diff --git a/scripts/Makefile b/scripts/Makefile index bba2cd1..c7df219 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.4 2004/09/07 16:19:43 rich Exp $ +# $Id: Makefile,v 1.5 2004/09/07 16:58:03 rich Exp $ include ../Makefile.config @@ -47,6 +47,7 @@ OBJS := create.cmo \ restore.cmo \ restore_form.cmo \ search.cmo \ + signup.cmo \ sitemap.cmo \ undelete_file.cmo \ undelete_file_form.cmo \ diff --git a/scripts/signup.ml b/scripts/signup.ml new file mode 100644 index 0000000..ea90b34 --- /dev/null +++ b/scripts/signup.ml @@ -0,0 +1,90 @@ +(* COCANWIKI scripts. + * Written by Richard W.M. Jones . + * 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 diff --git a/templates/login_form.html b/templates/login_form.html index 534ca6a..02c9843 100644 --- a/templates/login_form.html +++ b/templates/login_form.html @@ -47,7 +47,7 @@ ::if(create_account_anon):: -
+ @@ -57,12 +57,12 @@ - + - + -- 1.8.3.1
Password:
Password again: