Store exip in Results struct
This commit is contained in:
parent
b6f133de90
commit
8b76a569fd
|
@ -86,14 +86,15 @@ function response(survey::SurveyID, response::ResponseID; cache::Bool=true)
|
||||||
qid => Answer{anstype}(value, nothing)
|
qid => Answer{anstype}(value, nothing)
|
||||||
end)
|
end)
|
||||||
metadata = SearchLight.query(
|
metadata = SearchLight.query(
|
||||||
"SELECT started, completed, page \
|
"SELECT exip, started, completed, page \
|
||||||
FROM responses WHERE survey=$survey AND id=$response")
|
FROM responses WHERE survey=$survey AND id=$response")
|
||||||
|
exip = UInt32(metadata.exip[1])
|
||||||
started = parse(DateTime, metadata.started[1])
|
started = parse(DateTime, metadata.started[1])
|
||||||
completed = if !ismissing(metadata.completed[1])
|
completed = if !ismissing(metadata.completed[1])
|
||||||
parse(DateTime, metadata.completed[1]) end
|
parse(DateTime, metadata.completed[1]) end
|
||||||
RESPONSES[survey][response] =
|
RESPONSES[survey][response] =
|
||||||
Response(survey, response, metadata.page[1], answers,
|
Response(survey, response, exip, metadata.page[1],
|
||||||
started, completed)
|
answers, started, completed)
|
||||||
end
|
end
|
||||||
RESPONSES[survey][response]
|
RESPONSES[survey][response]
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,10 +40,13 @@ function new()
|
||||||
@info "client ip: $ip"
|
@info "client ip: $ip"
|
||||||
xor(reinterpret(UInt32, Genie.Encryption.encrypt(rand(UInt8, 4)) |> hex2bytes)...)
|
xor(reinterpret(UInt32, Genie.Encryption.encrypt(rand(UInt8, 4)) |> hex2bytes)...)
|
||||||
end
|
end
|
||||||
r = Surveys.Response(SURVEY, vcat(responseids(SURVEY),
|
exip = encrypted_xord_ip()
|
||||||
Vector{Surveys.ResponseID}(keys(INPROGRESS) |> collect)))
|
r = Surveys.Response(SURVEY,
|
||||||
|
vcat(responseids(SURVEY),
|
||||||
|
Vector{Surveys.ResponseID}(keys(INPROGRESS) |> collect));
|
||||||
|
exip)
|
||||||
INPROGRESS[r.id] = r
|
INPROGRESS[r.id] = r
|
||||||
register!(r, encrypted_xord_ip())
|
register!(r, exip)
|
||||||
uid_str = string(r.id, base=UID_ENCBASE)
|
uid_str = string(r.id, base=UID_ENCBASE)
|
||||||
Genie.Renderer.redirect(HTTP.URIs.URI(currenturl()).path * "?uid=$uid_str&page=1")
|
Genie.Renderer.redirect(HTTP.URIs.URI(currenturl()).path * "?uid=$uid_str&page=1")
|
||||||
end
|
end
|
||||||
|
|
|
@ -226,7 +226,8 @@ const ResponseID = UInt32
|
||||||
mutable struct Response
|
mutable struct Response
|
||||||
survey::SurveyID
|
survey::SurveyID
|
||||||
id::ResponseID
|
id::ResponseID
|
||||||
page::Integer
|
exip::UInt32
|
||||||
|
page::Int
|
||||||
answers::Dict{Symbol, Answer}
|
answers::Dict{Symbol, Answer}
|
||||||
started::DateTime
|
started::DateTime
|
||||||
completed::Union{DateTime, Nothing}
|
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)
|
Answer(::Question{<:FormField{T}}) where {T} = Answer{T}(missing, nothing)
|
||||||
|
|
||||||
Response(s::Survey, id::ResponseID=rand(ResponseID)) =
|
Response(s::Survey, id::ResponseID=rand(ResponseID); exip::UInt32=zero(UInt32)) =
|
||||||
Response(s.id, id, 1,
|
Response(s.id, id, exip, 1,
|
||||||
Dict(q.id => Answer(q) for q in
|
Dict(q.id => Answer(q) for q in
|
||||||
Iterators.flatten([s[i].questions for i in 1:length(s)])),
|
Iterators.flatten([s[i].questions for i in 1:length(s)])),
|
||||||
now(), nothing)
|
now(), nothing)
|
||||||
|
|
||||||
function Response(s::Survey, oldids::Vector{ResponseID})
|
function Response(s::Survey, oldids::Vector{ResponseID}; exip::UInt32=zero(UInt32))
|
||||||
newid = rand(ResponseID)
|
newid = rand(ResponseID)
|
||||||
while newid in oldids
|
while newid in oldids
|
||||||
newid = rand(ResponseID)
|
newid = rand(ResponseID)
|
||||||
end
|
end
|
||||||
Response(s, newid)
|
Response(s, newid; exip)
|
||||||
end
|
end
|
||||||
|
|
||||||
interpret(::FormField{<:AbstractString}, value::AbstractString) = value
|
interpret(::FormField{<:AbstractString}, value::AbstractString) = value
|
||||||
|
|
Loading…
Reference in New Issue