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