forked from AkkomaGang/akkoma
Add an ability to disabled captcha
This commit is contained in:
parent
a2399c1c7c
commit
28c43a417e
3 changed files with 37 additions and 18 deletions
|
@ -11,6 +11,7 @@
|
||||||
config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes
|
config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes
|
||||||
|
|
||||||
config :pleroma, Pleroma.Captcha,
|
config :pleroma, Pleroma.Captcha,
|
||||||
|
enabled: false,
|
||||||
method: Pleroma.Captcha.Kocaptcha
|
method: Pleroma.Captcha.Kocaptcha
|
||||||
|
|
||||||
# Kocaptcha is a very simple captcha service, the source code is here: https://github.com/koto-bank/kocaptcha
|
# Kocaptcha is a very simple captcha service, the source code is here: https://github.com/koto-bank/kocaptcha
|
||||||
|
|
|
@ -28,6 +28,15 @@ def validate(token, captcha) do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
def handle_call(:new, _from, state) do
|
def handle_call(:new, _from, state) do
|
||||||
|
enabled = Pleroma.Config.get([__MODULE__, :enabled])
|
||||||
|
|
||||||
|
if !enabled do
|
||||||
|
{
|
||||||
|
:reply,
|
||||||
|
%{type: :none},
|
||||||
|
state
|
||||||
|
}
|
||||||
|
else
|
||||||
method = Pleroma.Config.get!([__MODULE__, :method])
|
method = Pleroma.Config.get!([__MODULE__, :method])
|
||||||
|
|
||||||
case method do
|
case method do
|
||||||
|
@ -51,6 +60,7 @@ def handle_call(:new, _from, state) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
def handle_call({:validate, token, captcha}, _from, state) do
|
def handle_call({:validate, token, captcha}, _from, state) do
|
||||||
|
|
|
@ -137,8 +137,16 @@ def register_user(params) do
|
||||||
captcha_token: params["captcha_token"]
|
captcha_token: params["captcha_token"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 invalid
|
# Captcha invalid
|
||||||
if not Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution]) do
|
if not captcha_ok do
|
||||||
# I have no idea how this error handling works
|
# I have no idea how this error handling works
|
||||||
{:error, %{error: Jason.encode!(%{captcha: ["Invalid CAPTCHA"]})}}
|
{:error, %{error: Jason.encode!(%{captcha: ["Invalid CAPTCHA"]})}}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue