@lanodan @McMongoose @sjw @fba @hj @sapphire
here you go have fun
defmodule Pleroma.Hcaptcha do @moduledoc "Captcha for the Eth.co contact form" @doc "Checks token validation with hCaptcha" @spec is_valid_token?(String.t()) :: boolean() def is_valid_token?(token) do secret = Application.get_env(:pleroma, :hcaptcha)[:secret] params = %{secret: secret, response: token} client = make_client() hostname = Pleroma.Web.Endpoint.host() with {:ok, %Tesla.Env{body: body}} <- Tesla.post(client, "/siteverify", params), true <- match?( %{ "hostname" => ^hostname, "success" => true }, body ) do true else _ -> false end end defp make_client do middleware = [ {Tesla.Middleware.BaseUrl, "https://hcaptcha.com"}, Tesla.Middleware.FormUrlencoded, Tesla.Middleware.JSON ] Tesla.client(middleware) end end