(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki.ml,v 1.4 2004/11/10 16:52:04 rich Exp $
+ * $Id: cocanwiki.ml,v 1.7 2005/11/21 15:28:36 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
open Cocanwiki_ok
open Cocanwiki_strings
-module Pool = DbiPool (Dbi_postgres)
+module Pool = DbiPool (Dbi_postgresql)
(* This function is used to grab a database handle. It's used in a couple
* of very special places, and is not for general consumption.
*)
if q#param_exists "cookie" then (
let value = q#param "cookie" in
- let cookie = Cookie.cookie ~name:"auth" ~value ~path:"/" () in
- Table.set (Request.headers_out r) "Set-Cookie" cookie#as_string;
+ let cookie = Cookie.cookie "auth" value ~path:"/" in
+ Table.set (Request.headers_out r) "Set-Cookie" cookie#to_string;
value
) else (
(* Normal cookie, from the headers. *)
(* Call the actual CGI script. *)
run r q dbh hostid host user
) else (
- if user = Anonymous then
- q#redirect ("http://" ^ hostname ^ "/_login")
- else
+ if user = Anonymous then (
+ (* Not logged in and no permission to do the requested action,
+ * so redirect to the login script. If possible set the
+ * redirect parameter so that we return to the right URL.
+ *)
+ let redirect =
+ try
+ (* If we passed through mod_rewrite, then it saved the
+ * unmodified original URL in a subprocess environment
+ * variable called SCRIPT_URL:
+ *)
+ let tbl = Request.subprocess_env r in
+ Some (Table.get tbl "SCRIPT_URL")
+ with
+ Not_found ->
+ try
+ (* Otherwise try the ordinary uri field in request_rec. *)
+ Some (Request.uri r)
+ with Not_found ->
+ None in
+
+ let url =
+ "http://" ^ hostname ^ "/_login" ^
+ match redirect with
+ | None -> ""
+ | Some url -> "?redirect=" ^ Cgi_escape.escape_url url in
+ q#redirect url
+ ) else
error ~back_button:true
~title:"Access denied"
q "You do not have permission to access this part of the site."