mirror of
https://github.com/plausible/analytics.git
synced 2024-12-18 23:11:43 +03:00
9feda6a3d3
* Add HCaptcha support * Actually verify password reset requests * Fix password request when captcha not configured * Add configuration for prod release
28 lines
587 B
Elixir
28 lines
587 B
Elixir
defmodule PlausibleWeb.Captcha do
|
|
@verify_endpoint "https://hcaptcha.com/siteverify"
|
|
|
|
def enabled? do
|
|
!!sitekey()
|
|
end
|
|
|
|
def sitekey() do
|
|
Application.get_env(:plausible, :hcaptcha, [])
|
|
|> Keyword.fetch!(:sitekey)
|
|
end
|
|
|
|
def verify(token) do
|
|
if enabled?() do
|
|
res = HTTPoison.post!(@verify_endpoint, {:form, [{"response", token}, {"secret", secret()}]})
|
|
json = Jason.decode!(res.body)
|
|
json["success"]
|
|
else
|
|
true
|
|
end
|
|
end
|
|
|
|
defp secret() do
|
|
Application.get_env(:plausible, :hcaptcha, [])
|
|
|> Keyword.fetch!(:secret)
|
|
end
|
|
end
|