aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/captcha.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma/captcha.ex')
-rw-r--r--lib/pleroma/captcha.ex52
1 files changed, 31 insertions, 21 deletions
diff --git a/lib/pleroma/captcha.ex b/lib/pleroma/captcha.ex
index 31f3bc797..ffa5640ea 100644
--- a/lib/pleroma/captcha.ex
+++ b/lib/pleroma/captcha.ex
@@ -28,27 +28,37 @@ defmodule Pleroma.Captcha do
@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