All new templates. Site menu displays basically everywhere.
[cocanwiki.git] / scripts / logout.ml
1 (* Easy Web Pages (EWP) scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: logout.ml,v 1.2 2004/09/09 09:35:33 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open Cocanwiki
13 open Cocanwiki_ok
14
15 let expires = "Sun, 09-Sep-2001 02:46:40 GMT"
16
17 let run r (q : cgi) (dbh : Dbi.connection) _ _ user =
18   (* The logout function removes all of the associated cookies from the
19    * database.  This isn't required, but is nice semantics, and also helps
20    * to reduce the size of the usercookies table in the database.
21    *)
22   (match user with
23        Anonymous -> ()
24      | User (userid, _, _) ->
25          let sth = dbh#prepare_cached "delete from usercookies
26                                         where userid = ?" in
27          sth#execute [`Int userid];
28
29          dbh#commit ()
30   );
31
32   let cookie =
33     Cookie.cookie ~name:"auth" ~value:"none" ~path:"/" ~expires () in
34
35   ok ~title:"Logged out" ~buttons:[ok_button "/"] ~cookie
36     q "You have been logged out."
37
38 let () =
39   register_script run