Commit 30039246 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Share scopes in each module

parent d6468942
...@@ -35,6 +35,8 @@ end ...@@ -35,6 +35,8 @@ end
module Make (C : CONFIG) (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct module Make (C : CONFIG) (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct
let scope = Eliom_common.default_session_scope
let cas_login = Eliom_service.external_service let cas_login = Eliom_service.external_service
~prefix:C.server ~prefix:C.server
~path:["login"] ~path:["login"]
...@@ -63,13 +65,8 @@ module Make (C : CONFIG) (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct ...@@ -63,13 +65,8 @@ module Make (C : CONFIG) (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct
let self = let self =
Eliom_uri.make_string_uri ~absolute:true ~service () |> rewrite_prefix Eliom_uri.make_string_uri ~absolute:true ~service () |> rewrite_prefix
let login_cont = Eliom_reference.eref let login_cont = Eliom_reference.eref ~scope None
~scope:Eliom_common.default_session_scope let logout_cont = Eliom_reference.eref ~scope None
None
let logout_cont = Eliom_reference.eref
~scope:Eliom_common.default_session_scope
None
let () = Eliom_registration.Any.register let () = Eliom_registration.Any.register
~service:login_cas ~service:login_cas
......
...@@ -37,26 +37,25 @@ let parse_config ~instance ~attributes = ...@@ -37,26 +37,25 @@ let parse_config ~instance ~attributes =
module Make (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct module Make (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct
let scope = Eliom_common.default_session_scope
let service = Eliom_service.service let service = Eliom_service.service
~path:N.path ~path:N.path
~get_params:Eliom_parameter.unit ~get_params:Eliom_parameter.unit
() ()
let login_cont = Eliom_reference.eref let login_cont = Eliom_reference.eref ~scope None
~scope:Eliom_common.default_session_scope
None
let () = Eliom_registration.Html5.register ~service let () = Eliom_registration.Html5.register ~service
(fun () () -> (fun () () ->
let post_params = Eliom_parameter.(string "username") in let post_params = Eliom_parameter.(string "username") in
let service = Eliom_service.post_coservice let service = Eliom_service.post_coservice
~csrf_safe:true ~csrf_safe:true
~csrf_scope:Eliom_common.default_session_scope ~csrf_scope:scope
~fallback:service ~fallback:service
~post_params () ~post_params ()
in in
let () = Eliom_registration.Any.register ~service let () = Eliom_registration.Any.register ~service ~scope
~scope:Eliom_common.default_session_scope
(fun () user_name -> (fun () user_name ->
match_lwt Eliom_reference.get login_cont with match_lwt Eliom_reference.get login_cont with
| Some cont -> | Some cont ->
......
...@@ -42,6 +42,8 @@ end ...@@ -42,6 +42,8 @@ end
module Make (C : CONFIG) (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct module Make (C : CONFIG) (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct
let scope = Eliom_common.default_session_scope
let service = Eliom_service.service let service = Eliom_service.service
~path:N.path ~path:N.path
~get_params:Eliom_parameter.unit ~get_params:Eliom_parameter.unit
...@@ -55,9 +57,7 @@ module Make (C : CONFIG) (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct ...@@ -55,9 +57,7 @@ module Make (C : CONFIG) (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct
| _ -> failwith ("error while parsing db file for " ^ N.name) | _ -> failwith ("error while parsing db file for " ^ N.name)
) SMap.empty (Csv.load C.db) ) SMap.empty (Csv.load C.db)
let login_cont = Eliom_reference.eref let login_cont = Eliom_reference.eref ~scope None
~scope:Eliom_common.default_session_scope
None
let () = Eliom_registration.Html5.register ~service let () = Eliom_registration.Html5.register ~service
(fun () () -> (fun () () ->
...@@ -66,12 +66,11 @@ module Make (C : CONFIG) (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct ...@@ -66,12 +66,11 @@ module Make (C : CONFIG) (N : NAME) (T : TEMPLATES) : AUTH_HANDLERS = struct
) in ) in
let service = Eliom_service.post_coservice let service = Eliom_service.post_coservice
~csrf_safe:true ~csrf_safe:true
~csrf_scope:Eliom_common.default_session_scope ~csrf_scope:scope
~fallback:service ~fallback:service
~post_params () ~post_params ()
in in
let () = Eliom_registration.Any.register ~service let () = Eliom_registration.Any.register ~service ~scope
~scope:Eliom_common.default_session_scope
(fun () (user_name, password) -> (fun () (user_name, password) ->
if ( if (
try try
......
...@@ -60,12 +60,12 @@ end ...@@ -60,12 +60,12 @@ end
module Make (N : CONFIG) = struct module Make (N : CONFIG) = struct
let scope = Eliom_common.default_session_scope
let auth_instances = Hashtbl.create 10 let auth_instances = Hashtbl.create 10
let auth_instance_names = ref [] let auth_instance_names = ref []
let user = Eliom_reference.eref let user = Eliom_reference.eref ~scope None
~scope:Eliom_common.default_session_scope
None
module Services : AUTH_SERVICES = struct module Services : AUTH_SERVICES = struct
......
...@@ -295,10 +295,6 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} = ...@@ -295,10 +295,6 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} =
module Register (S : SITE_SERVICES) (T : ELECTION_TEMPLATES) : EMPTY = struct module Register (S : SITE_SERVICES) (T : ELECTION_TEMPLATES) : EMPTY = struct
open Eliom_registration open Eliom_registration
let ballot = Eliom_reference.eref
~scope:Eliom_common.default_session_scope
(None : string option)
let if_eligible acl f () x = let if_eligible acl f () x =
lwt user = S.get_user () in lwt user = S.get_user () in
if acl metadata user then if acl metadata user then
...@@ -306,9 +302,10 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} = ...@@ -306,9 +302,10 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} =
else else
forbidden () forbidden ()
let cast_confirmed = Eliom_reference.eref let scope = Eliom_common.default_session_scope
~scope:Eliom_common.default_session_scope
None let ballot = Eliom_reference.eref ~scope None
let cast_confirmed = Eliom_reference.eref ~scope None
let () = Html5.register ~service:W.S.home let () = Html5.register ~service:W.S.home
(if_eligible can_read (if_eligible can_read
...@@ -470,16 +467,13 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} = ...@@ -470,16 +467,13 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} =
let confirm () = let confirm () =
let service = Eliom_service.post_coservice let service = Eliom_service.post_coservice
~csrf_safe:true ~csrf_safe:true
~csrf_scope:Eliom_common.default_session_scope ~csrf_scope:scope
~fallback:W.S.election_cast ~fallback:W.S.election_cast
~post_params:Eliom_parameter.unit ~post_params:Eliom_parameter.unit
() ()
in in
let () = Any.register let () = Any.register ~service ~scope do_cast in
~service service
~scope:Eliom_common.default_session_scope
do_cast
in service
in in
let can_vote = can_vote metadata user in let can_vote = can_vote metadata user in
T.cast_confirmation ~confirm ~user ~can_vote () T.cast_confirmation ~confirm ~user ~can_vote ()
......
...@@ -59,6 +59,8 @@ module Make (C : CONFIG) : SITE_SERVICES = struct ...@@ -59,6 +59,8 @@ module Make (C : CONFIG) : SITE_SERVICES = struct
include Auth.Services include Auth.Services
open Eliom_parameter open Eliom_parameter
let scope = Eliom_common.default_session_scope
let home = service let home = service
~path:(make_path [""]) ~path:(make_path [""])
~get_params:unit ~get_params:unit
...@@ -74,8 +76,7 @@ module Make (C : CONFIG) : SITE_SERVICES = struct ...@@ -74,8 +76,7 @@ module Make (C : CONFIG) : SITE_SERVICES = struct
~get_params:unit ~get_params:unit
() ()
let saved_service = Eliom_reference.eref let saved_service = Eliom_reference.eref ~scope
~scope:Eliom_common.default_session_scope
(module struct let s = home end : SAVED_SERVICE) (module struct let s = home end : SAVED_SERVICE)
let cont () = let cont () =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment