config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes
config :pleroma, Pleroma.Captcha,
+ enabled: false,
method: Pleroma.Captcha.Kocaptcha
# Kocaptcha is a very simple captcha service, the source code is here: https://github.com/koto-bank/kocaptcha
@doc false
def handle_call(:new, _from, state) do
- method = Pleroma.Config.get!([__MODULE__, :method])
-
- case method do
- __MODULE__.Kocaptcha ->
- endpoint = Pleroma.Config.get!([method, :endpoint])
- case HTTPoison.get(endpoint <> "/new") do
- {:error, _} ->
- %{error: "Kocaptcha service unavailable"}
- {:ok, res} ->
- json_resp = Poison.decode!(res.body)
-
- token = json_resp["token"]
-
- true = :ets.insert(@ets, {token, json_resp["md5"]})
-
- {
- :reply,
- %{type: :kocaptcha, token: token, url: endpoint <> json_resp["url"]},
- state
- }
- end
+ enabled = Pleroma.Config.get([__MODULE__, :enabled])
+
+ if !enabled do
+ {
+ :reply,
+ %{type: :none},
+ state
+ }
+ else
+ method = Pleroma.Config.get!([__MODULE__, :method])
+
+ case method do
+ __MODULE__.Kocaptcha ->
+ endpoint = Pleroma.Config.get!([method, :endpoint])
+ case HTTPoison.get(endpoint <> "/new") do
+ {:error, _} ->
+ %{error: "Kocaptcha service unavailable"}
+ {:ok, res} ->
+ json_resp = Poison.decode!(res.body)
+
+ token = json_resp["token"]
+
+ true = :ets.insert(@ets, {token, json_resp["md5"]})
+
+ {
+ :reply,
+ %{type: :kocaptcha, token: token, url: endpoint <> json_resp["url"]},
+ state
+ }
+ end
+ end
end
end
captcha_token: params["captcha_token"]
}
+ captcha_enabled = Pleroma.Config.get([Pleroma.Captcha, :enabled])
+ # true if captcha is disabled or enabled and valid, false otherwise
+ captcha_ok = if !captcha_enabled do
+ true
+ else
+ Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution])
+ end
+
# Captcha invalid
- if not Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution]) do
+ if not captcha_ok do
# I have no idea how this error handling works
{:error, %{error: Jason.encode!(%{captcha: ["Invalid CAPTCHA"]})}}
else