diff --git a/app/resources/results/Results.jl b/app/resources/results/Results.jl index 44b0b4b..4a0bae4 100644 --- a/app/resources/results/Results.jl +++ b/app/resources/results/Results.jl @@ -86,14 +86,15 @@ function response(survey::SurveyID, response::ResponseID; cache::Bool=true) qid => Answer{anstype}(value, nothing) end) metadata = SearchLight.query( - "SELECT started, completed, page \ + "SELECT exip, started, completed, page \ FROM responses WHERE survey=$survey AND id=$response") + exip = UInt32(metadata.exip[1]) started = parse(DateTime, metadata.started[1]) completed = if !ismissing(metadata.completed[1]) parse(DateTime, metadata.completed[1]) end RESPONSES[survey][response] = - Response(survey, response, metadata.page[1], answers, - started, completed) + Response(survey, response, exip, metadata.page[1], + answers, started, completed) end RESPONSES[survey][response] end diff --git a/app/resources/surveys/SurveysController.jl b/app/resources/surveys/SurveysController.jl index 0b4233d..99bed52 100644 --- a/app/resources/surveys/SurveysController.jl +++ b/app/resources/surveys/SurveysController.jl @@ -40,10 +40,13 @@ function new() @info "client ip: $ip" xor(reinterpret(UInt32, Genie.Encryption.encrypt(rand(UInt8, 4)) |> hex2bytes)...) end - r = Surveys.Response(SURVEY, vcat(responseids(SURVEY), - Vector{Surveys.ResponseID}(keys(INPROGRESS) |> collect))) + exip = encrypted_xord_ip() + r = Surveys.Response(SURVEY, + vcat(responseids(SURVEY), + Vector{Surveys.ResponseID}(keys(INPROGRESS) |> collect)); + exip) INPROGRESS[r.id] = r - register!(r, encrypted_xord_ip()) + register!(r, exip) uid_str = string(r.id, base=UID_ENCBASE) Genie.Renderer.redirect(HTTP.URIs.URI(currenturl()).path * "?uid=$uid_str&page=1") end diff --git a/lib/Surveys.jl b/lib/Surveys.jl index dcfb8c2..4170788 100644 --- a/lib/Surveys.jl +++ b/lib/Surveys.jl @@ -226,7 +226,8 @@ const ResponseID = UInt32 mutable struct Response survey::SurveyID id::ResponseID - page::Integer + exip::UInt32 + page::Int answers::Dict{Symbol, Answer} started::DateTime completed::Union{DateTime, Nothing} @@ -242,18 +243,18 @@ Base.getindex(r::Response, id::Symbol) = r.answers[id] Answer(::Question{<:FormField{T}}) where {T} = Answer{T}(missing, nothing) -Response(s::Survey, id::ResponseID=rand(ResponseID)) = - Response(s.id, id, 1, +Response(s::Survey, id::ResponseID=rand(ResponseID); exip::UInt32=zero(UInt32)) = + Response(s.id, id, exip, 1, Dict(q.id => Answer(q) for q in Iterators.flatten([s[i].questions for i in 1:length(s)])), now(), nothing) -function Response(s::Survey, oldids::Vector{ResponseID}) +function Response(s::Survey, oldids::Vector{ResponseID}; exip::UInt32=zero(UInt32)) newid = rand(ResponseID) while newid in oldids newid = rand(ResponseID) end - Response(s, newid) + Response(s, newid; exip) end interpret(::FormField{<:AbstractString}, value::AbstractString) = value