(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: create_user.ml,v 1.8 2006/07/26 16:34:18 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *) open Apache open Registry open Cgi open Printf open Cocanwiki open Cocanwiki_ok open Cocanwiki_strings let run r (q : cgi) dbh hostid _ _ = 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" dbh hostid q "The username or password you gave is empty."; return () ); if password1 <> password2 then ( error ~back_button:true ~title:"Passwords don't match" dbh hostid q "The two passwords you gave aren't identical."; return () ); let password = password1 in if UTF8.length username > 32 || UTF8.length password > 128 then ( error ~back_button:true ~title:"Username or password too long" dbh hostid q "Usernames should be less than 32 characters long. For passwords we let you have a generous 128 characters."; return () ); (* Not a duplicate? *) let rows = PGSQL(dbh) "select id from users where hostid = $hostid and name = $username" in (match rows with | [_] -> error ~back_button:true ~title:"Username already taken" dbh hostid q "Someone has already taken that username."; return () | [] -> () | _ -> assert false ); let can_edit = q#param_true "can_edit" in let can_manage_users = q#param_true "can_manage_users" in let can_manage_contacts = q#param_true "can_manage_contacts" in let can_manage_site = q#param_true "can_manage_site" in let can_edit_global_css = q#param_true "can_edit_global_css" in let can_import_mail = q#param_true "can_import_mail" in let can_edit_macros = q#param_true "can_edit_macros" in let force_password_change = q#param_true "force_password_change" in (* Create the user account. *) PGSQL(dbh) "insert into users (name, password, hostid, can_edit, can_manage_users, can_manage_contacts, can_manage_site, can_edit_global_css, can_import_mail, can_edit_macros, force_password_change) values ($username, $password, $hostid, $can_edit, $can_manage_users, $can_manage_contacts, $can_manage_site, $can_edit_global_css, $can_import_mail, $can_edit_macros, $force_password_change)"; PGOCaml.commit dbh; let buttons = [ ok_button "/_users" ] in ok ~title:"Account created" ~buttons dbh hostid q ("An account was created for " ^ username ^ ".") let () = register_script ~restrict:[CanManageUsers] run