X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Flogin.ml;h=1132798fc8d8ad645e29db9091897939956e46e6;hb=cd059731a60fd3d4dcf426430ad26ff227b91910;hp=4594e6b2ef30518403874b27b9f7fa4139f8fe6a;hpb=ca058886bab9dfe4e5ca23ea0e52649bd5c9e9be;p=cocanwiki.git diff --git a/scripts/login.ml b/scripts/login.ml index 4594e6b..1132798 100644 --- a/scripts/login.ml +++ b/scripts/login.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: login.ml,v 1.7 2005/11/21 15:28:35 rich Exp $ + * $Id: login.ml,v 1.11 2006/03/28 16:24:07 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 @@ -29,63 +29,60 @@ open Cocanwiki_ok let expires = "Wed, 18-May-2033 04:33:20 GMT" -let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = +let run r (q : cgi) dbh hostid _ _ = let username = q#param "username" in let password = q#param "password" in let permanent = try "1" = q#param "permanent" with Not_found -> false in let redirect = try q#param "redirect" with Not_found -> "/" in - let sth = dbh#prepare_cached "select id, force_password_change from users - where name = ? and password = ? - and hostid = ?" in - sth#execute [`String username; `String password; `Int hostid]; + let rows = PGSQL(dbh) + "select id, force_password_change from users + where name = $username and password = $password and hostid = $hostid" in - try - let userid, force_password_change = - match sth#fetch1 () with - [ `Int userid; `Bool force_password_change ] -> - userid, force_password_change - | _ -> assert false in + let userid, force_password_change = + match rows with + | [] -> + error + ~title:"Bad name or password" + ~back_button:true + dbh hostid q "The name or password was wrong."; + return () + | [ row ] -> row + | _ -> assert false 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]; + (* Create a cookie. *) + let cookie = random_sessionid () in + PGSQL(dbh) "insert into usercookies (userid, cookie) + values ($userid, $cookie)"; - dbh#commit (); + PGOCaml.commit dbh; - (* Force password change? *) - let redirect = - if force_password_change then "/_bin/change_password_form.cmo" - else redirect in + (* Force password change? *) + let redirect = + if force_password_change then "/_bin/change_password_form.cmo" + else redirect in - let cookie = - if permanent then - Cookie.cookie "auth" cookie ~path:"/" ~expires - else - Cookie.cookie "auth" cookie ~path:"/" in + let cookie = + if permanent then + Cookie.cookie "auth" cookie ~path:"/" ~expires + else + Cookie.cookie "auth" cookie ~path:"/" in - let ok_button = ok_button redirect in - let buttons = - if redirect <> "/" && redirect <> "/index" then ( - ok_button :: - [ { Template.StdPages.label = " Home Page "; - Template.StdPages.link = "/"; - Template.StdPages.method_ = None; - Template.StdPages.params = [] } ] - ) else [ ok_button ] in + let ok_button = ok_button redirect in + let buttons = + if redirect <> "/" && redirect <> "/index" then ( + ok_button :: + [ { Template.StdPages.label = " Home Page "; + Template.StdPages.link = "/"; + Template.StdPages.method_ = None; + Template.StdPages.params = [] } ] + ) else [ ok_button ] in - ok ~title:"Logged in" ~buttons ~cookie - q ("Welcome " ^ username ^ "." ^ - if force_password_change then " Please change your password now." - else "") - with - Not_found -> - error - ~title:"Bad name or password" - ~back_button:true - q "The name or password was wrong." + ok ~title:"Logged in" ~buttons ~cookie + dbh hostid q + ("Welcome " ^ username ^ "." ^ + if force_password_change then " Please change your password now." + else "") let () = register_script run