forked from AkkomaGang/akkoma
Formatting fixes
This commit is contained in:
parent
b5518da904
commit
23549d3952
4 changed files with 18 additions and 18 deletions
|
@ -15,8 +15,7 @@
|
||||||
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
|
||||||
config :pleroma, Pleroma.Captcha.Kocaptcha,
|
config :pleroma, Pleroma.Captcha.Kocaptcha, endpoint: "http://localhost:9093"
|
||||||
endpoint: "http://localhost:9093"
|
|
||||||
|
|
||||||
# Upload configuration
|
# Upload configuration
|
||||||
config :pleroma, Pleroma.Upload,
|
config :pleroma, Pleroma.Upload,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
defmodule Pleroma.Captcha.Service do
|
defmodule Pleroma.Captcha.Service do
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Request new captcha from a captcha service.
|
Request new captcha from a captcha service.
|
||||||
|
|
||||||
|
@ -20,5 +19,5 @@ defmodule Pleroma.Captcha.Service do
|
||||||
|
|
||||||
`true` if captcha is valid, `false` if not
|
`true` if captcha is valid, `false` if not
|
||||||
"""
|
"""
|
||||||
@callback validate(token :: String.t, captcha :: String.t) :: boolean
|
@callback validate(token :: String.t(), captcha :: String.t()) :: boolean
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,9 +7,11 @@ defmodule Pleroma.Captcha.Kocaptcha do
|
||||||
@impl Service
|
@impl Service
|
||||||
def new() do
|
def new() do
|
||||||
endpoint = Pleroma.Config.get!([__MODULE__, :endpoint])
|
endpoint = Pleroma.Config.get!([__MODULE__, :endpoint])
|
||||||
|
|
||||||
case HTTPoison.get(endpoint <> "/new") do
|
case HTTPoison.get(endpoint <> "/new") do
|
||||||
{:error, _} ->
|
{:error, _} ->
|
||||||
%{error: "Kocaptcha service unavailable"}
|
%{error: "Kocaptcha service unavailable"}
|
||||||
|
|
||||||
{:ok, res} ->
|
{:ok, res} ->
|
||||||
json_resp = Poison.decode!(res.body)
|
json_resp = Poison.decode!(res.body)
|
||||||
|
|
||||||
|
@ -25,7 +27,7 @@ def new() do
|
||||||
def validate(token, captcha) do
|
def validate(token, captcha) do
|
||||||
with false <- is_nil(captcha),
|
with false <- is_nil(captcha),
|
||||||
[{^token, saved_md5}] <- :ets.lookup(@ets, token),
|
[{^token, saved_md5}] <- :ets.lookup(@ets, token),
|
||||||
true <- (:crypto.hash(:md5, captcha) |> Base.encode16) == String.upcase(saved_md5) do
|
true <- :crypto.hash(:md5, captcha) |> Base.encode16() == String.upcase(saved_md5) do
|
||||||
# Clear the saved value
|
# Clear the saved value
|
||||||
:ets.delete(@ets, token)
|
:ets.delete(@ets, token)
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,8 @@ def register_user(params) do
|
||||||
|
|
||||||
captcha_enabled = Pleroma.Config.get([Pleroma.Captcha, :enabled])
|
captcha_enabled = Pleroma.Config.get([Pleroma.Captcha, :enabled])
|
||||||
# true if captcha is disabled or enabled and valid, false otherwise
|
# true if captcha is disabled or enabled and valid, false otherwise
|
||||||
captcha_ok = if !captcha_enabled do
|
captcha_ok =
|
||||||
|
if !captcha_enabled do
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution])
|
Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution])
|
||||||
|
@ -174,7 +175,6 @@ def register_user(params) do
|
||||||
{:error, %{error: errors}}
|
{:error, %{error: errors}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
!registrations_open && is_nil(token) ->
|
!registrations_open && is_nil(token) ->
|
||||||
{:error, "Invalid token"}
|
{:error, "Invalid token"}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue