]> matita.cs.unibo.it Git - helm.git/blobdiff - matitaB/matita/matitaAuthentication.ml
When the user db is not found, matitaweb now creates a new one.
[helm.git] / matitaB / matita / matitaAuthentication.ml
index 7d6471df5b4848bade59340b548e2431e7cd4269..d51eb2e4fae4a4ff7c0d2b0bb9ea508f049a7b3c 100644 (file)
@@ -39,6 +39,8 @@ exception UsernameCollision of string
 
 let lookup_user uid = List.assoc uid !user_tbl
 
+let user_of_session sid = let res,_,_ = List.assoc sid !session_tbl in res
+
 let create_session uid =
   let status = new MatitaEngine.status (Some uid) "cic:/matita" in
   let history = [status] in
@@ -102,9 +104,12 @@ let serialize () =
 ;;
 
 let deserialize () =
-  let utbl_ch = open_in (config_path () ^ "/usertable.dump") in
-  user_tbl := Marshal.from_channel utbl_ch;
-  close_in utbl_ch;
+  (try
+    let utbl_ch = open_in (config_path () ^ "/usertable.dump") in
+    user_tbl := Marshal.from_channel utbl_ch;
+    close_in utbl_ch;
+  with
+    | Sys_error _ -> user_tbl := []);
   (* old_sessions are now invalid *)
   session_tbl := [];
 ;;
@@ -114,6 +119,14 @@ let add_user uid pw =
     let _ = lookup_user uid in
     raise (UsernameCollision uid)
   with Not_found -> 
+    MatitaFilesystem.checkout uid;
     user_tbl := (uid,(pw,None))::!user_tbl;
     serialize ()
 ;;
+
+let reset () =
+  user_tbl := [];
+  session_tbl := [];
+  MatitaFilesystem.reset_lib ();
+  serialize ();
+;;