From 9121e9f2de9f4df3e909e30a127214bb0f01c019 Mon Sep 17 00:00:00 2001 From: Wilmer Ricciotti Date: Wed, 15 Jun 2011 16:15:09 +0000 Subject: [PATCH] (Almost) working multi-user matitaweb. --- matitaB/matita/logout.html | 15 ++++++++++++ matitaB/matita/matitadaemon.ml | 44 +++++++++++++++++++++++++++------- matitaB/matita/netplex.conf | 13 +++++++--- matitaB/matita/register.html | 27 +++++++++++++++++++++ 4 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 matitaB/matita/logout.html create mode 100644 matitaB/matita/register.html diff --git a/matitaB/matita/logout.html b/matitaB/matita/logout.html new file mode 100644 index 000000000..df0ae2001 --- /dev/null +++ b/matitaB/matita/logout.html @@ -0,0 +1,15 @@ + + + + + + + + + +

Logout succeeded!

+ +

Start a new session

+ + + diff --git a/matitaB/matita/matitadaemon.ml b/matitaB/matita/matitadaemon.ml index 07b03207a..492edd56e 100644 --- a/matitaB/matita/matitadaemon.ml +++ b/matitaB/matita/matitadaemon.ml @@ -218,6 +218,25 @@ let advance0 sid text = MatitaAuthentication.set_history sid (st::history); parsed_len, new_unparsed, st +let register (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = + let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in + let env = cgi#environment in + + assert (cgi#arguments <> []); + let uid = cgi#argument_value "userid" in + let userpw = cgi#argument_value "password" in + (try + MatitaAuthentication.add_user uid userpw; + env#set_output_header_field "Location" "/index.html" + with MatitaAuthentication.UsernameCollision _ -> + cgi#set_header + ~cache:`No_cache + ~content_type:"text/html; charset=\"utf-8\"" + (); + cgi#out_channel#output_string + "Error: User id collision!"); + cgi#out_channel#commit_work() +;; let login (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in @@ -235,8 +254,10 @@ let login (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = begin prerr_endline "4"; let sid = MatitaAuthentication.create_session uid in - let cookie = Netcgi.Cookie.make "session" (Uuidm.to_string sid) in - cgi#set_header ~status:`See_other ~cache:`No_cache ~set_cookies:[cookie] (); + (* let cookie = Netcgi.Cookie.make "session" (Uuidm.to_string sid) in + cgi#set_header ~set_cookies:[cookie] (); *) + env#set_output_header_field + "Set-Cookie" ("session=" ^ (Uuidm.to_string sid)); env#set_output_header_field "Location" "/index.html" end else @@ -438,6 +459,13 @@ let start() = dyn_translator = (fun _ -> ""); (* not needed *) dyn_accept_all_conditionals = false; } in + let do_register = + { Nethttpd_services.dyn_handler = (fun _ -> register); + dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered; + dyn_uri = None; (* not needed *) + dyn_translator = (fun _ -> ""); (* not needed *) + dyn_accept_all_conditionals = false; + } in let do_login = { Nethttpd_services.dyn_handler = (fun _ -> login); dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered; @@ -445,13 +473,13 @@ let start() = dyn_translator = (fun _ -> ""); (* not needed *) dyn_accept_all_conditionals = false; } in - (*let do_logout = + let do_logout = { Nethttpd_services.dyn_handler = (fun _ -> logout); dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered; dyn_uri = None; (* not needed *) dyn_translator = (fun _ -> ""); (* not needed *) dyn_accept_all_conditionals = false; - } in *) + } in let nethttpd_factory = Nethttpd_plex.nethttpd_factory @@ -459,14 +487,12 @@ let start() = ; "retract", do_retract ; "bottom", goto_bottom ; "open", retrieve + ; "register", do_register ; "login", do_login - (*; "logout", do_logout *)] + ; "logout", do_logout ] () in MatitaInit.initialize_all (); - (* test begin *) - MatitaAuthentication.add_user "ricciott" "pippo123"; - MatitaAuthentication.add_user "asperti" "pluto456"; - (* test end *) + MatitaAuthentication.deserialize (); Netplex_main.startup parallelizer Netplex_log.logger_factories (* allow all built-in logging styles *) diff --git a/matitaB/matita/netplex.conf b/matitaB/matita/netplex.conf index 0728b01ca..52178dee4 100644 --- a/matitaB/matita/netplex.conf +++ b/matitaB/matita/netplex.conf @@ -27,7 +27,7 @@ netplex { path = "/"; service { type = "file"; - docroot = "/home/ricciott/matitaB/matita"; + docroot = "/home/barolo/matitaB/matita"; media_types_file = "/etc/mime.types"; enable_listings = true; } @@ -60,6 +60,13 @@ netplex { handler = "bottom"; } }; + uri { + path = "/register"; + service { + type = "dynamic"; + handler = "register"; + } + }; uri { path = "/login"; service { @@ -67,13 +74,13 @@ netplex { handler = "login"; } }; - (* uri { + uri { path = "/logout"; service { type = "dynamic"; handler = "logout"; } - };*) + }; }; }; workload_manager { diff --git a/matitaB/matita/register.html b/matitaB/matita/register.html new file mode 100644 index 000000000..4f60e2d3a --- /dev/null +++ b/matitaB/matita/register.html @@ -0,0 +1,27 @@ + + + + + + + + +
+ + + + + + + + + +
User id:
Password:
+ + + +
+ + + + -- 2.39.2