Store exip in Results struct

This commit is contained in:
TEC 2022-10-18 19:54:40 +08:00
parent b6f133de90
commit 8b76a569fd
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
3 changed files with 16 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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