Commit 6b9be734 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Remove SAVED_SERVICE

SITE_SERVICES.cont is now an Eliom reference that can be directly used
wherever a continuation is expected.
parent 17ee34a3
...@@ -136,7 +136,7 @@ module Make (N : CONFIG) = struct ...@@ -136,7 +136,7 @@ module Make (N : CONFIG) = struct
end end
module Register (C : CONT_SERVICE) (T : TEMPLATES) : EMPTY = struct module Register (S : SITE_SERVICES) (T : TEMPLATES) : EMPTY = struct
let () = login_choose := T.login_choose let () = login_choose := T.login_choose
...@@ -169,17 +169,15 @@ module Make (N : CONFIG) = struct ...@@ -169,17 +169,15 @@ module Make (N : CONFIG) = struct
let () = Eliom_registration.Any.register let () = Eliom_registration.Any.register
~service:Services.login ~service:Services.login
(fun service () -> (fun service () ->
let cont () () = lwt cont = Eliom_reference.get S.cont in
C.cont () >>= Eliom_registration.Redirection.send login_handler service cont
in login_handler service cont
) )
let () = Eliom_registration.Any.register let () = Eliom_registration.Any.register
~service:Services.logout ~service:Services.logout
(fun () () -> (fun () () ->
let cont () () = lwt cont = Eliom_reference.get S.cont in
C.cont () >>= Eliom_registration.Redirection.send Services.do_logout cont ()
in Services.do_logout cont ()
) )
end end
......
...@@ -41,5 +41,5 @@ end ...@@ -41,5 +41,5 @@ end
module Make (C : CONFIG) : sig module Make (C : CONFIG) : sig
module Services : AUTH_SERVICES module Services : AUTH_SERVICES
module Register (S : CONT_SERVICE) (T : TEMPLATES) : EMPTY module Register (S : SITE_SERVICES) (T : TEMPLATES) : EMPTY
end end
...@@ -310,9 +310,8 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} = ...@@ -310,9 +310,8 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} =
let () = Html5.register ~service:W.S.home let () = Html5.register ~service:W.S.home
(if_eligible can_read (if_eligible can_read
(fun user () -> (fun user () ->
let module X = struct let s = W.S.home end in let cont () () = Redirection.send W.S.home in
let x = (module X : SAVED_SERVICE) in Eliom_reference.set S.cont cont >>
Eliom_reference.set S.saved_service x >>
match_lwt Eliom_reference.get cast_confirmed with match_lwt Eliom_reference.get cast_confirmed with
| Some result -> | Some result ->
Eliom_reference.unset cast_confirmed >> Eliom_reference.unset cast_confirmed >>
...@@ -383,11 +382,11 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} = ...@@ -383,11 +382,11 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} =
let () = Any.register let () = Any.register
~service:W.S.election_dir ~service:W.S.election_dir
(fun f () -> (fun f () ->
let module X = struct let cont () () =
let s = Eliom_service.preapply W.S.election_dir f Eliom_service.preapply W.S.election_dir f |>
end in Redirection.send
let x = (module X : SAVED_SERVICE) in in
Eliom_reference.set S.saved_service x >> Eliom_reference.set S.cont cont >>
handle_pseudo_file () f handle_pseudo_file () f
) )
...@@ -428,9 +427,8 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} = ...@@ -428,9 +427,8 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} =
(if_eligible can_read (if_eligible can_read
(fun user () -> (fun user () ->
Eliom_reference.unset ballot >> Eliom_reference.unset ballot >>
let module X = struct let s = W.S.election_vote end in let cont () () = Redirection.send W.S.election_vote in
let x = (module X : SAVED_SERVICE) in Eliom_reference.set S.cont cont >>
Eliom_reference.set S.saved_service x >>
return W.S.booth return W.S.booth
) )
) )
...@@ -483,16 +481,15 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} = ...@@ -483,16 +481,15 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} =
(if_eligible can_read (if_eligible can_read
(fun user () -> (fun user () ->
let uuid = W.election.e_params.e_uuid in let uuid = W.election.e_params.e_uuid in
let module X = struct let s = W.S.election_cast end in let cont () () = Redirection.send W.S.election_cast in
let x = (module X : SAVED_SERVICE) in Eliom_reference.set S.cont cont >>
Eliom_reference.set S.saved_service x >>
match_lwt Eliom_reference.get ballot with match_lwt Eliom_reference.get ballot with
| Some _ -> ballot_received uuid user | Some _ -> ballot_received uuid user
| None -> T.cast_raw () | None -> T.cast_raw ()
) )
) )
let () = Redirection.register let () = Any.register
~service:W.S.election_cast_post ~service:W.S.election_cast_post
(if_eligible can_read (if_eligible can_read
(fun user (ballot_raw, ballot_file) -> (fun user (ballot_raw, ballot_file) ->
...@@ -503,16 +500,12 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} = ...@@ -503,16 +500,12 @@ let make {raw_election; metadata; featured; params_fname; public_keys_fname} =
Lwt_stream.to_string (Lwt_io.chars_of_file fname) Lwt_stream.to_string (Lwt_io.chars_of_file fname)
| _, _ -> fail_http 400 | _, _ -> fail_http 400
in in
let module X : SAVED_SERVICE = struct let cont () () = Redirection.send W.S.election_cast in
let uuid = W.election.e_params.e_uuid Eliom_reference.set S.cont cont >>
let s = W.S.election_cast
end in
let x = (module X : SAVED_SERVICE) in
Eliom_reference.set S.saved_service x >>
Eliom_reference.set ballot (Some the_ballot) >> Eliom_reference.set ballot (Some the_ballot) >>
match user with match user with
| None -> return (Eliom_service.preapply S.login None) | None -> S.do_login cont ()
| Some u -> S.cont () | Some u -> cont () ()
) )
) )
......
...@@ -24,17 +24,6 @@ open Serializable_t ...@@ -24,17 +24,6 @@ open Serializable_t
open Web_serializable_t open Web_serializable_t
open Signatures open Signatures
module type SAVED_SERVICE = sig
val s :
(unit, unit,
[> `Attached of
([> `Internal of [> `Service ] ], [> `Get ])
Eliom_service.a_s ],
[ `WithoutSuffix ], unit, unit,
[> Eliom_service.registrable ], 'a)
Eliom_service.service
end
type election_config = { type election_config = {
raw_election : string; raw_election : string;
metadata : metadata; metadata : metadata;
...@@ -72,8 +61,6 @@ module type CORE_SERVICES = sig ...@@ -72,8 +61,6 @@ module type CORE_SERVICES = sig
[< Eliom_service.registrable > `Registrable ], 'a) [< Eliom_service.registrable > `Registrable ], 'a)
Eliom_service.service Eliom_service.service
val saved_service : (module SAVED_SERVICE) Eliom_reference.eref
end end
module type ELECTION_SERVICES = sig module type ELECTION_SERVICES = sig
...@@ -157,17 +144,6 @@ module type ELECTION_SERVICES = sig ...@@ -157,17 +144,6 @@ module type ELECTION_SERVICES = sig
end end
module type CONT_SERVICE = sig
val cont :
unit ->
(unit, unit,
[> `Attached of
([> `External | `Internal of [> `Service ] ], [> `Get ])
Eliom_service.a_s ],
[ `WithoutSuffix ], unit, unit, Eliom_service.registrable, 'a)
Eliom_service.service Lwt.t
end
type service_handler = unit -> type service_handler = unit ->
(Eliom_registration.browser_content, (Eliom_registration.browser_content,
Eliom_registration.http_service Eliom_registration.http_service
...@@ -270,13 +246,14 @@ end ...@@ -270,13 +246,14 @@ end
module type SITE_SERVICES = sig module type SITE_SERVICES = sig
include CORE_SERVICES include CORE_SERVICES
include CONT_SERVICE
include AUTH_SERVICES include AUTH_SERVICES
val register_election : election_config -> (module WEB_ELECTION) Lwt.t val register_election : election_config -> (module WEB_ELECTION) Lwt.t
val set_main_election : (module WEB_ELECTION) -> unit val set_main_election : (module WEB_ELECTION) -> unit
val unset_main_election : unit -> unit val unset_main_election : unit -> unit
val cont : (unit -> service_handler) Eliom_reference.eref
end end
module type TEMPLATES = sig module type TEMPLATES = sig
......
...@@ -76,13 +76,8 @@ module Make (C : CONFIG) : SITE_SERVICES = struct ...@@ -76,13 +76,8 @@ module Make (C : CONFIG) : SITE_SERVICES = struct
~get_params:unit ~get_params:unit
() ()
let saved_service = Eliom_reference.eref ~scope let cont = Eliom_reference.eref ~scope
(module struct let s = home end : SAVED_SERVICE) (fun () () -> Eliom_registration.Redirection.send home)
let cont () =
lwt x = Eliom_reference.get saved_service in
let module X = (val x : SAVED_SERVICE) in
return X.s
let register_election config = !register_election_ref config let register_election config = !register_election_ref config
...@@ -108,7 +103,7 @@ module Make (C : CONFIG) : SITE_SERVICES = struct ...@@ -108,7 +103,7 @@ module Make (C : CONFIG) : SITE_SERVICES = struct
let () = Any.register ~service:home let () = Any.register ~service:home
(fun () () -> (fun () () ->
Eliom_reference.unset saved_service >> Eliom_reference.unset cont >>
match !main_election with match !main_election with
| None -> | None ->
T.home ~featured:!featured () >>= Html5.send T.home ~featured:!featured () >>= Html5.send
......
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