aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/config.exs3
-rw-r--r--lib/pleroma/captcha/captcha_service.ex3
-rw-r--r--lib/pleroma/captcha/kocaptcha.ex4
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api.ex26
4 files changed, 18 insertions, 18 deletions
diff --git a/config/config.exs b/config/config.exs
index 32593045c..b7d439e9d 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -15,8 +15,7 @@ config :pleroma, Pleroma.Captcha,
method: Pleroma.Captcha.Kocaptcha
# Kocaptcha is a very simple captcha service, the source code is here: https://github.com/koto-bank/kocaptcha
-config :pleroma, Pleroma.Captcha.Kocaptcha,
- endpoint: "http://localhost:9093"
+config :pleroma, Pleroma.Captcha.Kocaptcha, endpoint: "http://localhost:9093"
# Upload configuration
config :pleroma, Pleroma.Upload,
diff --git a/lib/pleroma/captcha/captcha_service.ex b/lib/pleroma/captcha/captcha_service.ex
index ae1d6e7c7..907a73ad0 100644
--- a/lib/pleroma/captcha/captcha_service.ex
+++ b/lib/pleroma/captcha/captcha_service.ex
@@ -1,5 +1,4 @@
defmodule Pleroma.Captcha.Service do
-
@doc """
Request new captcha from a captcha service.
@@ -20,5 +19,5 @@ defmodule Pleroma.Captcha.Service do
`true` if captcha is valid, `false` if not
"""
- @callback validate(token :: String.t, captcha :: String.t) :: boolean
+ @callback validate(token :: String.t(), captcha :: String.t()) :: boolean
end
diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex
index abccbf6d3..173ce17f7 100644
--- a/lib/pleroma/captcha/kocaptcha.ex
+++ b/lib/pleroma/captcha/kocaptcha.ex
@@ -7,9 +7,11 @@ defmodule Pleroma.Captcha.Kocaptcha do
@impl Service
def new() do
endpoint = Pleroma.Config.get!([__MODULE__, :endpoint])
+
case HTTPoison.get(endpoint <> "/new") do
{:error, _} ->
%{error: "Kocaptcha service unavailable"}
+
{:ok, res} ->
json_resp = Poison.decode!(res.body)
@@ -25,7 +27,7 @@ defmodule Pleroma.Captcha.Kocaptcha do
def validate(token, captcha) do
with false <- is_nil(captcha),
[{^token, saved_md5}] <- :ets.lookup(@ets, token),
- true <- (:crypto.hash(:md5, captcha) |> Base.encode16) == String.upcase(saved_md5) do
+ true <- :crypto.hash(:md5, captcha) |> Base.encode16() == String.upcase(saved_md5) do
# Clear the saved value
:ets.delete(@ets, token)
diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex
index 9f98c43c9..90b8345c5 100644
--- a/lib/pleroma/web/twitter_api/twitter_api.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api.ex
@@ -139,11 +139,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
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_ok =
+ if !captcha_enabled do
+ true
+ else
+ Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution])
+ end
# Captcha invalid
if not captcha_ok do
@@ -155,8 +156,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
# no need to query DB if registration is open
token =
unless registrations_open || is_nil(tokenString) do
- Repo.get_by(UserInviteToken, %{token: tokenString})
- end
+ Repo.get_by(UserInviteToken, %{token: tokenString})
+ end
cond do
registrations_open || (!is_nil(token) && !token.used) ->
@@ -168,18 +169,17 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
else
{:error, changeset} ->
errors =
- Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end)
- |> Jason.encode!()
+ Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end)
+ |> Jason.encode!()
- {:error, %{error: errors}}
+ {:error, %{error: errors}}
end
-
!registrations_open && is_nil(token) ->
- {:error, "Invalid token"}
+ {:error, "Invalid token"}
!registrations_open && token.used ->
- {:error, "Expired token"}
+ {:error, "Expired token"}
end
end
end