]> matita.cs.unibo.it Git - helm.git/commitdiff
(Almost) working multi-user matitaweb.
authorWilmer Ricciotti <ricciott@cs.unibo.it>
Wed, 15 Jun 2011 16:15:09 +0000 (16:15 +0000)
committerWilmer Ricciotti <ricciott@cs.unibo.it>
Wed, 15 Jun 2011 16:15:09 +0000 (16:15 +0000)
matitaB/matita/logout.html [new file with mode: 0644]
matitaB/matita/matitadaemon.ml
matitaB/matita/netplex.conf
matitaB/matita/register.html [new file with mode: 0644]

diff --git a/matitaB/matita/logout.html b/matitaB/matita/logout.html
new file mode 100644 (file)
index 0000000..df0ae20
--- /dev/null
@@ -0,0 +1,15 @@
+<html>
+<head>
+</head>
+                 
+<head>
+<script type="text/javascript" src="matitaweb.js"></script>
+</head>
+
+<body onLoad="delete_session();">
+       <p>Logout succeeded!</p>
+
+       <p><A href="/login.html">Start a new session</A></p>
+</body>
+</html> 
+
index 07b03207a7ec4b7774af7bd19ad889b7019bb0ab..492edd56e425ac73b9fcbee296021942f288aadb 100644 (file)
@@ -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
+      "<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
@@ -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 *)
index 0728b01ca526a58bd542b73b580cd995d71e73db..52178dee496daea15f3c3e7d2ec317c6c3ea6270 100644 (file)
@@ -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 (file)
index 0000000..4f60e2d
--- /dev/null
@@ -0,0 +1,27 @@
+<html>
+<head>
+</head>
+                 
+<head></head>
+
+<body>
+
+<FORM action="register" method="post">
+<table>
+  <tr>
+  <td>User id: </td>
+  <td><INPUT type="TEXT" name="userid"></td>
+  </tr>
+  <tr>
+  <td>Password: </td>
+  <td><INPUT type="PASSWORD" name="password"></td>
+  </tr>
+</table>
+
+<INPUT type="SUBMIT" value="Register">
+<INPUT type="RESET" value="Reset">
+</FORM>
+
+</body>
+</html> 
+