Commit 8e86cbe9 authored by Stephane Glondu's avatar Stephane Glondu

Add a button to send again a password

parent de0ef68c
......@@ -44,7 +44,8 @@ let election_setup_questions_post = post_coservice ~fallback:election_setup_ques
let election_setup_description = post_coservice ~fallback:election_setup ~post_params:(string "name" ** string "description") ()
let election_setup_voters = service ~path:["setup"; "voters"] ~get_params:(uuid "uuid") ()
let election_setup_voters_add = post_service ~fallback:election_setup_voters ~post_params:(string "voters") ()
let election_setup_voters_remove = post_service ~fallback:election_setup_voters ~post_params:(string "voter") ()
let election_setup_voters_remove = post_coservice ~fallback:election_setup_voters ~post_params:(string "voter") ()
let election_setup_voters_passwd = post_coservice ~fallback:election_setup_voters ~post_params:(string "voter") ()
let election_setup_trustee_add = post_coservice ~fallback:election_setup ~post_params:unit ()
let election_setup_trustee_del = post_coservice ~fallback:election_setup ~post_params:unit ()
let election_setup_credential_authority = service ~path:["setup"; "credential-authority"] ~get_params:(uuid "uuid") ()
......
......@@ -498,26 +498,28 @@ let generate_password title url id =
send_email "noreply@belenios.org" email subject body >>
return (salt, hashed)
let handle_password se uuid ~force voters =
let title = se.se_questions.t_name in
let url = Eliom_uri.make_string_uri ~absolute:true ~service:election_home
(uuid, ()) |> rewrite_prefix
in
Lwt_list.iter_s (fun id ->
match id.sv_password with
| Some _ when not force -> return_unit
| None | Some _ ->
lwt x = generate_password title url id.sv_id in
return (id.sv_password <- Some x)
) voters >>
return (fun () ->
T.generic_page ~title:"Success"
"Passwords have been generated and mailed!" () >>= Html5.send)
let () =
Any.register
~service:election_setup_auth_genpwd
(handle_setup
(fun se () _ uuid ->
let title = se.se_questions.t_name in
let url = Eliom_uri.make_string_uri
~absolute:true ~service:election_home
(uuid, ()) |> rewrite_prefix
in
Lwt_list.iter_s (fun id ->
match id.sv_password with
| None ->
lwt x = generate_password title url id.sv_id in
return (id.sv_password <- Some x)
| Some _ -> return_unit
) se.se_voters >>
return (fun () ->
T.generic_page ~title:"Success"
"Passwords have been generated and mailed!" () >>= Html5.send)))
handle_password se uuid ~force:false se.se_voters))
let () =
Any.register
......@@ -644,6 +646,13 @@ let () =
) se.se_voters;
return (redir_preapply election_setup_voters uuid))))
let () =
Any.register ~service:election_setup_voters_passwd
(handle_setup
(fun se voter _ uuid ->
let voter = List.filter (fun v -> v.sv_id = voter) se.se_voters in
handle_password se uuid ~force:true voter))
let () =
Redirection.register
~service:election_setup_trustee_add
......
......@@ -630,15 +630,25 @@ let election_setup_voters uuid se () =
| Some [{auth_system = "password"; _}] -> true
| _ -> false
in
let to_string x = match x with
| Some _ -> "Yes"
| None -> "No"
let mk_regen_passwd value =
post_form ~service:election_setup_voters_passwd
~a:[a_style "display: inline;"]
(fun name ->
[
string_input ~input_type:`Hidden ~name ~value ();
string_input ~input_type:`Submit ~value:"Send again" ();
]
) uuid
in
let format_password_cell x = match x.sv_password with
| Some _ -> [pcdata "Yes "; mk_regen_passwd x.sv_id]
| None -> [pcdata "No"]
in
let voters =
List.map (fun v ->
tr (
[td [pcdata v.sv_id]] @
(if has_passwords then [td [pcdata (to_string v.sv_password)]] else []) @
(if has_passwords then [td (format_password_cell v)] else []) @
(if se.se_public_creds_received then [] else [td [mk_remove_button v.sv_id]])
)
) se.se_voters
......@@ -660,7 +670,7 @@ let election_setup_voters uuid se () =
table
(tr (
[th [pcdata "Identity"]] @
(if has_passwords then [th [pcdata "Password"]] else []) @
(if has_passwords then [th [pcdata "Password sent?"]] else []) @
(if se.se_public_creds_received then [] else [th [pcdata "Remove"]])
) :: voters)
]
......
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