1 defmodule Pleroma.Captcha.Kocaptcha do
2 alias Pleroma.Captcha.Service
9 endpoint = Pleroma.Config.get!([__MODULE__, :endpoint])
10 case HTTPoison.get(endpoint <> "/new") do
12 %{error: "Kocaptcha service unavailable"}
14 json_resp = Poison.decode!(res.body)
16 token = json_resp["token"]
18 true = :ets.insert(@ets, {token, json_resp["md5"]})
20 %{type: :kocaptcha, token: token, url: endpoint <> json_resp["url"]}
25 def validate(token, captcha) do
26 with false <- is_nil(captcha),
27 [{^token, saved_md5}] <- :ets.lookup(@ets, token),
28 true <- (:crypto.hash(:md5, captcha) |> Base.encode16) == String.upcase(saved_md5) do
29 # Clear the saved value
30 :ets.delete(@ets, token)