mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-01 06:14:07 +00:00
6da6540036
Done via the following command:
git diff fcd5dd259a
--stat --name-only | xargs sed -i '/Pleroma Authors/c# Copyright © 2017-2020 Pleroma Authors <https:\/\/pleroma.social\/>'
36 lines
932 B
Elixir
36 lines
932 B
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Captcha.Native do
|
|
import Pleroma.Web.Gettext
|
|
alias Pleroma.Captcha.Service
|
|
@behaviour Service
|
|
|
|
@impl Service
|
|
def new do
|
|
case Captcha.get() do
|
|
:error ->
|
|
%{error: dgettext("errors", "Captcha error")}
|
|
|
|
{:ok, answer_data, img_binary} ->
|
|
%{
|
|
type: :native,
|
|
token: token(),
|
|
url: "data:image/png;base64," <> Base.encode64(img_binary),
|
|
answer_data: answer_data
|
|
}
|
|
end
|
|
end
|
|
|
|
@impl Service
|
|
def validate(_token, captcha, captcha) when not is_nil(captcha), do: :ok
|
|
def validate(_token, _captcha, _answer), do: {:error, dgettext("errors", "Invalid CAPTCHA")}
|
|
|
|
defp token do
|
|
10
|
|
|> :crypto.strong_rand_bytes()
|
|
|> Base.url_encode64(padding: false)
|
|
end
|
|
end
|