Commit 369595dc authored by Stephane Glondu's avatar Stephane Glondu

Avoid new tabs and use download links

New tabs tend to be blocked by browsers nowadays.
parent fc99b869
......@@ -60,7 +60,18 @@ let get_input id =
| None -> raise Not_found
| Some x -> x
let hide_element_by_id id =
let set_element_display id x =
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e -> e##style##display <- Js.string "none")
(fun e -> e##style##display <- Js.string x)
let hide_element_by_id id = set_element_display id "none"
let set_download id mime fn x =
let x = (Js.string ("data:" ^ mime ^ ","))##concat (Js.encodeURI (Js.string x)) in
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e ->
e##setAttribute (Js.string "download", Js.string fn);
Js.Opt.iter (Dom_html.CoerceTo.a e) (fun e -> e##href <- x)
)
......@@ -49,12 +49,10 @@ let generate _ =
let text_pks = pubs |> List.sort compare |> String.concat "\n" in
set_textarea "pks" text_pks;
let text_creds = (privs |> List.rev |> String.concat "\n") ^ "\n" in
let data_creds = (Js.string "data:text/plain,")##concat (Js.encodeURI (Js.string text_creds)) in
ignore (Dom_html.window##open_ (data_creds, Js.string "creds", Js.null));
set_download "creds" "text/plain" "creds.txt" text_creds;
let text_hashed = (hashs |> List.rev |> String.concat "\n") ^ "\n" in
let data_hashed = (Js.string "data:text/plain,")##concat (Js.encodeURI (Js.string text_hashed)) in
ignore (Dom_html.window##open_ (data_hashed, Js.string "hashed", Js.null));
alert "New windows (or tabs) were open with private credentials and credential hashes. Please save them before submitting public credentials!";
set_download "hashed" "text/plain" "hashed.txt" text_hashed;
set_element_display "submit_form" "inline";
Js._false
let fill_interactivity _ =
......
......@@ -28,11 +28,10 @@ let tkeygen _ =
end in
let module X = (val make (module P : PARAMS) : S) in
let open X in
let {id; priv; pub} = trustee_keygen () in
let data_uri = (Js.string "data:application/json,")##concat (Js.encodeURI (Js.string priv)) in
ignore (Dom_html.window##open_ (data_uri, Js.string id, Js.null));
let {id=_; priv; pub} = trustee_keygen () in
set_textarea "pk" pub;
alert "The private key has been open in a new window (or tab). Please save it before submitting the public key!";
set_download "private_key" "application/json" "private_key.json" priv;
set_element_display "submit_form" "inline";
Js._false
let fill_interactivity _ =
......
......@@ -36,11 +36,10 @@ let gen_cert e _ =
e##innerHTML <- Js.string "";
let t = document##createTextNode (Js.string (Printf.sprintf "Certificate %s has been generated!" id)) in
Dom.appendChild e t;
let data_uri = Js.string ("data:text/plain," ^ key) in
ignore (Dom_html.window##open_ (data_uri, Js.string id, Js.null));
set_download "private_key" "text/plain" "private_key.txt" key;
set_element_display "key_helper" "block";
let cert = string_of_cert cert in
set_textarea "data" cert;
alert "The private key has been open in a new window (or tab). Please save it before submitting the certificate!";
Js._false
let proceed step e textarea _ =
......
......@@ -985,13 +985,22 @@ let election_setup_credentials token uuid se () =
]
in
let form_textarea =
post_form
post_form ~a:[a_id "submit_form"; a_style "display:none;"]
~service:election_setup_credentials_post
(fun name ->
[div
[div [pcdata "Public credentials:"];
div [textarea ~a:[a_id "pks"; a_rows 5; a_cols 40] ~name ()];
div [string_input ~input_type:`Submit ~value:"Submit" ()]]])
div [a ~service:home ~a:[a_id "creds"] [pcdata "Private credentials"] ()];
div ~a:[a_style "display:none;"] [a ~service:home ~a:[a_id "hashed"] [pcdata "Hashed public credentials"] ()];
div [
b [pcdata "Instructions:"];
ol [
li [pcdata "download private credentials using the link above;"];
li [pcdata "submit public credentials using the button below."];
];
];
div [string_input ~input_type:`Submit ~value:"Submit public credentials" ()]]])
token
in
let disclaimer =
......@@ -1080,10 +1089,18 @@ let election_setup_trustee token uuid se () =
~service
(fun name ->
[
div [
div ~a:[a_id "submit_form"; a_style "display:none;"] [
div [pcdata "Public key:"];
div [textarea ~a:[a_rows 5; a_cols 40; a_id "pk"] ~name ~value ()];
div [string_input ~input_type:`Submit ~value:"Submit" ()];
div [a ~service:home ~a:[a_id "private_key"] [pcdata "Private key"] ()];
div [
b [pcdata "Instructions:"];
ol [
li [pcdata "download your private key using the link above;"];
li [pcdata "submit your public key using the button below."];
];
];
div [string_input ~input_type:`Submit ~value:"Submit public key" ()];
]
]
) ()
......@@ -1179,6 +1196,14 @@ let election_setup_threshold_trustee token uuid se () =
~a:[a_id "data_form"]
(fun data ->
[
div ~a:[a_id "key_helper"; a_style "display:none;"] [
div [a ~service:home ~a:[a_id "private_key"] [pcdata "Private key"] ()];
b [pcdata "Instructions:"];
ol [
li [pcdata "download your private key using the link above;"];
li [pcdata "submit public data using the button below."];
];
];
div [
div [
pcdata "Data: ";
......
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