1 defmodule Pleroma.Captcha.Kocaptcha do
2 alias Pleroma.Captcha.Service
7 endpoint = Pleroma.Config.get!([__MODULE__, :endpoint])
9 case Tesla.get(endpoint <> "/new") do
11 %{error: "Kocaptcha service unavailable"}
14 json_resp = Poison.decode!(res.body)
18 token: json_resp["token"],
19 url: endpoint <> json_resp["url"],
20 answer_data: json_resp["md5"]
26 def validate(_token, captcha, answer_data) do
27 # Here the token is unsed, because the unencrypted captcha answer is just passed to method
28 if not is_nil(captcha) and
29 :crypto.hash(:md5, captcha) |> Base.encode16() == String.upcase(answer_data),
31 else: {:error, "Invalid CAPTCHA"}