- @doc false
- def handle_call(:new, _from, state) do
- enabled = Pleroma.Config.get([__MODULE__, :enabled])
+ defp validate_answer_data(token, answer_data) do
+ {secret, sign_secret} = secret_pair(token)
+
+ with false <- is_nil(answer_data),
+ {:ok, data} <- MessageEncryptor.decrypt(answer_data, secret, sign_secret),
+ %{at: at, answer_data: answer_md5} <- :erlang.binary_to_term(data) do
+ {:ok, %{at: at, answer_data: answer_md5}}
+ else
+ _ -> {:error, :invalid_answer_data}
+ end
+ end
+
+ defp validate_expiration(created_at) do
+ # If the time found is less than (current_time-seconds_valid) then the time has already passed
+ # Later we check that the time found is more than the presumed invalidatation time, that means
+ # that the data is still valid and the captcha can be checked
+
+ valid_if_after = DateTime.subtract!(DateTime.now_utc(), seconds_valid())
+
+ if DateTime.before?(created_at, valid_if_after) do
+ {:error, :expired}
+ else
+ :ok
+ end
+ end