X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=matitaB%2Fmatita%2FmatitaAuthentication.ml;h=77aeed15f599c24f73d476b71e81aad45cc593d3;hb=fba2975ffd09ffb30a60500725c9991421445f37;hp=06e7d9451b719144ecb7ca613da3650b6bcf40a6;hpb=6c702f5054d7975f76911ba62da9bfa33d3ed0fa;p=helm.git diff --git a/matitaB/matita/matitaAuthentication.ml b/matitaB/matita/matitaAuthentication.ml index 06e7d9451..77aeed15f 100644 --- a/matitaB/matita/matitaAuthentication.ml +++ b/matitaB/matita/matitaAuthentication.ml @@ -30,8 +30,8 @@ type user = string * (string * session_id option) let user_tbl = (ref [] : user list ref) -(* session table: (user id, session id), matita status *) -type session = (string * session_id) * MatitaEngine.status +(* session table: session id, (user id, matita status, matita history *) +type session = session_id * (string * MatitaEngine.status * MatitaEngine.status list) let session_tbl = (ref [] : session list ref) @@ -39,24 +39,49 @@ exception UsernameCollision of string let lookup_user uid = List.assoc uid !user_tbl -let create_session uid status = +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 let pw,sid = List.assoc uid !user_tbl in let clean_utbl = List.remove_assoc uid !user_tbl in let new_session = Uuidm.create `V4 in user_tbl := (uid,(pw,Some new_session))::clean_utbl; let clean_stbl = match sid with | Some sid' -> - List.remove_assoc (uid,sid') !session_tbl + List.remove_assoc sid' !session_tbl | _ -> !session_tbl - in session_tbl := ((uid,new_session),status)::clean_stbl + in + session_tbl := (new_session,(uid,status,history))::clean_stbl; + new_session ;; -let logout_user uid = - match List.assoc uid !user_tbl with - | _,None -> () - | pw, Some sid -> - user_tbl := (uid,(pw,None))::List.remove_assoc uid !user_tbl; - session_tbl := List.remove_assoc (uid,sid) !session_tbl +let get_session_owner sid = + let uid,_,_ = List.assoc sid !session_tbl + in uid + +let get_status sid = + let _,st,_ = List.assoc sid !session_tbl + in st + +let get_history sid = + let _,_,hist = List.assoc sid !session_tbl + in hist + +let set_status sid st = + let uid, oldst, hist = List.assoc sid !session_tbl in + session_tbl := (sid,(uid,st,hist))::(List.remove_assoc sid !session_tbl) + +let set_history sid hist = + let uid, st, oldhist = List.assoc sid !session_tbl in + session_tbl := (sid,(uid,st,hist))::(List.remove_assoc sid !session_tbl) + +let logout_user sid = + let uid,st,hist = List.assoc sid !session_tbl in + let pw,_ = List.assoc uid !user_tbl in + user_tbl := (uid,(pw,None))::List.remove_assoc uid !user_tbl; + session_tbl := List.remove_assoc sid !session_tbl ;; let remove_user uid = @@ -79,9 +104,13 @@ 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 := []; serialize()); (* old_sessions are now invalid *) session_tbl := []; ;; @@ -91,6 +120,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 (); +;;