1 defmodule Pleroma.Captcha do
4 @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}]
8 GenServer.start_link(__MODULE__, [], name: __MODULE__)
13 # Create a ETS table to store captchas
14 ets_name = Module.concat(method(), Ets)
15 ^ets_name = :ets.new(Module.concat(method(), Ets), @ets_options)
21 Ask the configured captcha service for a new captcha
24 GenServer.call(__MODULE__, :new)
28 Ask the configured captcha service to validate the captcha
30 def validate(token, captcha) do
31 GenServer.call(__MODULE__, {:validate, token, captcha})
35 def handle_call(:new, _from, state) do
36 enabled = Pleroma.Config.get([__MODULE__, :enabled])
39 {:reply, %{type: :none}, state}
41 {:reply, method().new(), state}
46 def handle_call({:validate, token, captcha}, _from, state) do
47 {:reply, method().validate(token, captcha), state}
50 defp method, do: Pleroma.Config.get!([__MODULE__, :method])