Commit 5642d1bb authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Add a confirmation page for election creation

parent e708731a
......@@ -56,6 +56,7 @@ let election_setup_credentials_server = post_coservice ~fallback:election_setup
let election_setup_trustees = service ~path:["setup"; "trustees"] ~get_params:(uuid "uuid") ()
let election_setup_trustee = service ~path:["setup"; "trustee"] ~get_params:(string "token") ()
let election_setup_trustee_post = post_coservice ~fallback:election_setup_trustee ~post_params:(string "public_key") ()
let election_setup_confirm = service ~path:["setup"; "confirm"] ~get_params:(uuid "uuid") ()
let election_setup_create = post_coservice ~csrf_safe:true ~fallback:election_setup ~post_params:unit ()
let election_setup_auth_genpwd = post_coservice ~fallback:election_setup ~post_params:unit ()
......
......@@ -803,6 +803,18 @@ let () =
)
)
let () =
Any.register
~service:election_setup_confirm
(fun uuid () ->
match_lwt Web_state.get_site_user () with
| None -> forbidden ()
| Some u ->
let uuid_s = Uuidm.to_string uuid in
lwt se = Ocsipersist.find election_stable uuid_s in
if se.se_owner <> u then forbidden () else
T.election_setup_confirm uuid se () >>= Html5.send)
let () =
Any.register
~service:election_setup_create
......
......@@ -461,17 +461,10 @@ let election_setup uuid se () =
)
]
in
let form_create =
post_form
~service:election_setup_create
(fun () ->
[div
[h2 [pcdata "Finalize creation"];
string_input ~input_type:`Submit ~value:"Create election" ();
pcdata " (Warning: this action is irreversible.)";
]]
) uuid
in
let link_confirm = div [
h2 [pcdata "Finalize creation"];
a ~service:election_setup_confirm [pcdata "Create election"] uuid;
] in
let content = [
div_description;
hr ();
......@@ -485,7 +478,7 @@ let election_setup uuid se () =
hr ();
div_trustees;
hr ();
form_create;
link_confirm;
] in
lwt login_box = site_login_box () in
base ~title ~login_box ~content ()
......@@ -893,6 +886,67 @@ let election_setup_import uuid se (elections, tallied, archived) () =
lwt login_box = site_login_box () in
base ~title ~login_box ~content ()
let election_setup_confirm uuid se () =
let title = "Election " ^ se.se_questions.t_name ^ " — Finalize creation" in
let voters = Printf.sprintf "%d voter(s)" (List.length se.se_voters) in
let passwords =
match se.se_metadata.e_auth_config with
| Some [{auth_system = "password"; _}] ->
if List.for_all (fun v -> v.sv_password <> None) se.se_voters then "OK"
else "Missing"
| _ -> "Not applicable"
in
let credentials =
if se.se_public_creds_received then "OK" else "Missing"
in
let trustees =
match se.se_public_keys with
| [] -> "OK"
| _ :: _ ->
if List.for_all (fun {st_public_key; _} ->
st_public_key <> ""
) se.se_public_keys then "OK" else "Missing"
in
let table_checklist = table [
tr [
td [pcdata "Voters?"];
td [pcdata voters];
];
tr [
td [pcdata "Passwords?"];
td [pcdata passwords];
];
tr [
td [pcdata "Credentials?"];
td [pcdata credentials];
];
tr [
td [pcdata "Trustees?"];
td [pcdata trustees];
]
] in
let checklist = div [
h2 [pcdata "Checklist"];
table_checklist;
] in
let form_create =
post_form
~service:election_setup_create
(fun () ->
[div
[h2 [pcdata "Finalize creation"];
string_input ~input_type:`Submit ~value:"Create election" ();
pcdata " (Warning: this action is irreversible.)";
]]
) uuid
in
let content = [
checklist;
form_create;
] in
lwt login_box = site_login_box () in
base ~title ~login_box ~content ()
let election_login_box w =
let module W = (val w : ELECTION_DATA) in
let module A = struct
......
......@@ -45,6 +45,7 @@ val election_setup_credentials : string -> string -> Web_common.setup_election -
val election_setup_trustees : Uuidm.t -> Web_common.setup_election -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_setup_trustee : string -> Web_common.setup_election -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_setup_import : Uuidm.t -> Web_common.setup_election -> (module ELECTION_DATA) list * (module ELECTION_DATA) list * (module ELECTION_DATA) list -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_setup_confirm : Uuidm.t -> Web_common.setup_election -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_home : (module ELECTION_DATA) -> Web_persist.election_state -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_admin : (module ELECTION_DATA) -> Web_serializable_j.metadata -> Web_persist.election_state -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
......
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