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
+ "<html><head></head><body>Error: User id collision!</body></html>");
+ 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
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
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;
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
; "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 *)