Commit a3caaa55 authored by Stephane Glondu's avatar Stephane Glondu

When importing voters from another election, also import passwords

parent 35aac12e
......@@ -119,3 +119,19 @@ let get_voters uuid =
lwt lines = Lwt_stream.to_list lines in
return @@ Some lines
with _ -> return_none
let get_passwords uuid =
let csv =
try Some (Csv.load (!spool_dir / uuid / "passwords.csv"))
with _ -> None
in
match csv with
| None -> return_none
| Some csv ->
let res = List.fold_left (fun accu line ->
match line with
| [login; salt; hash] ->
SMap.add login (salt, hash) accu
| _ -> accu
) SMap.empty csv in
return @@ Some res
......@@ -20,6 +20,7 @@
(**************************************************************************)
open Serializable_t
open Common
open Web_serializable_t
type election_state =
......@@ -47,3 +48,4 @@ val get_election_result : string -> Yojson.Safe.json result option Lwt.t
val get_elections_by_owner : user -> string list Lwt.t
val get_voters : string -> string list option Lwt.t
val get_passwords : string -> (string * string) SMap.t option Lwt.t
......@@ -636,7 +636,7 @@ let is_email x =
module SSet = Set.Make (PString)
let merge_voters a b =
let merge_voters a b f =
let existing = List.fold_left (fun accu sv ->
SSet.add sv.sv_id accu
) SSet.empty a in
......@@ -644,7 +644,7 @@ let merge_voters a b =
if SSet.mem sv_id existing then
(existing, accu)
else
(SSet.add sv_id existing, {sv_id; sv_password = None} :: accu)
(SSet.add sv_id existing, {sv_id; sv_password = f sv_id} :: accu)
) (existing, List.rev a) b in
List.rev res
......@@ -661,7 +661,7 @@ let () =
Printf.ksprintf failwith "%S is not a valid address" bad
with Not_found -> ()
in
se.se_voters <- merge_voters se.se_voters xs;
se.se_voters <- merge_voters se.se_voters xs (fun _ -> None);
return (redir_preapply election_setup_voters uuid))))
let () =
......@@ -1070,10 +1070,19 @@ let () =
(fun se from _ uuid ->
let from_s = Uuidm.to_string from in
lwt voters = Web_persist.get_voters from_s in
lwt passwords = Web_persist.get_passwords from_s in
let get_password =
match passwords with
| None -> fun _ -> None
| Some p -> fun sv_id ->
let _, login = split_identity sv_id in
try Some (SMap.find login p)
with Not_found -> None
in
match voters with
| Some voters ->
if se.se_public_creds_received then forbidden () else (
se.se_voters <- merge_voters se.se_voters voters;
se.se_voters <- merge_voters se.se_voters voters get_password;
return (redir_preapply election_setup_voters uuid))
| None ->
return (fun () -> T.generic_page ~title:"Error"
......
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