X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fcaptcha%2Fcaptcha.ex;h=a73b872517dc6b47c8386a79535bf8b8558c6852;hb=eae991b06a22bf7fc3eef7a0d5b409c931c1f6cb;hp=0207bcbea6261df88c000bb8d7b9d27d9c42ab2e;hpb=4258dd8633407587ca1f3dfe275afa6a91be9197;p=akkoma diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index 0207bcbea..a73b87251 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -3,14 +3,16 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Captcha do + import Pleroma.Web.Gettext + + alias Calendar.DateTime alias Plug.Crypto.KeyGenerator alias Plug.Crypto.MessageEncryptor - alias Calendar.DateTime use GenServer @doc false - def start_link() do + def start_link do GenServer.start_link(__MODULE__, [], name: __MODULE__) end @@ -22,7 +24,7 @@ defmodule Pleroma.Captcha do @doc """ Ask the configured captcha service for a new captcha """ - def new() do + def new do GenServer.call(__MODULE__, :new) end @@ -73,7 +75,7 @@ defmodule Pleroma.Captcha do secret = KeyGenerator.generate(secret_key_base, token <> "_encrypt") sign_secret = KeyGenerator.generate(secret_key_base, token <> "_sign") - # If the time found is less than (current_time - seconds_valid), then the time has already passed. + # If the time found is less than (current_time-seconds_valid) then the time has already passed # Later we check that the time found is more than the presumed invalidatation time, that means # that the data is still valid and the captcha can be checked seconds_valid = Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]) @@ -83,10 +85,11 @@ defmodule Pleroma.Captcha do with {:ok, data} <- MessageEncryptor.decrypt(answer_data, secret, sign_secret), %{at: at, answer_data: answer_md5} <- :erlang.binary_to_term(data) do try do - if DateTime.before?(at, valid_if_after), do: throw({:error, "CAPTCHA expired"}) + if DateTime.before?(at, valid_if_after), + do: throw({:error, dgettext("errors", "CAPTCHA expired")}) if not is_nil(Cachex.get!(:used_captcha_cache, token)), - do: throw({:error, "CAPTCHA already used"}) + do: throw({:error, dgettext("errors", "CAPTCHA already used")}) res = method().validate(token, captcha, answer_md5) # Throw if an error occurs @@ -101,7 +104,7 @@ defmodule Pleroma.Captcha do :throw, e -> e end else - _ -> {:error, "Invalid answer data"} + _ -> {:error, dgettext("errors", "Invalid answer data")} end {:reply, result, state}