diff options
author | rinpatch <rinpatch@sdf.org> | 2019-12-14 15:01:09 +0000 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2019-12-14 15:01:09 +0000 |
commit | ecb3386f939de3ffba16f9419994a009f2e59ded (patch) | |
tree | febe52f1b2cf59be4530ebc4f223f06e342c207c /lib/pleroma/captcha | |
parent | 0ba3f1ffb28792c21809fa9a30fc03a7a52d9361 (diff) | |
parent | 3b407a9a295da3f6c2fc91982088f066f2c3c711 (diff) | |
download | pleroma-1.1.7.tar.gz |
Merge branch 'release/1.1.7' into 'stable'v1.1.7
Release/1.1.7
See merge request pleroma/pleroma!2065
Diffstat (limited to 'lib/pleroma/captcha')
-rw-r--r-- | lib/pleroma/captcha/native.ex | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/pleroma/captcha/native.ex b/lib/pleroma/captcha/native.ex new file mode 100644 index 000000000..5306fe1aa --- /dev/null +++ b/lib/pleroma/captcha/native.ex @@ -0,0 +1,35 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 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 + {:timeout} -> + %{error: dgettext("errors", "Captcha timeout")} + + {: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 |