Merge pull request #5957 from blockscout/vb-csv-server-side-captcha
Server-side reCAPTCHA check for CSV exportpull/5963/head
commit
9e86794777
@ -0,0 +1,27 @@ |
||||
defmodule BlockScoutWeb.CaptchaHelper do |
||||
@moduledoc """ |
||||
A helper for CAPTCHA |
||||
""" |
||||
|
||||
@callback recaptcha_passed?(String.t() | nil) :: bool |
||||
@spec recaptcha_passed?(String.t() | nil) :: bool |
||||
def recaptcha_passed?(nil), do: false |
||||
|
||||
def recaptcha_passed?(recaptcha_response) do |
||||
re_captcha_secret_key = Application.get_env(:block_scout_web, :re_captcha_secret_key) |
||||
body = "secret=#{re_captcha_secret_key}&response=#{recaptcha_response}" |
||||
|
||||
headers = [{"Content-type", "application/x-www-form-urlencoded"}] |
||||
|
||||
case HTTPoison.post("https://www.google.com/recaptcha/api/siteverify", body, headers, []) do |
||||
{:ok, %HTTPoison.Response{status_code: 200, body: body}} -> |
||||
case Jason.decode!(body) do |
||||
%{"success" => true} -> true |
||||
_ -> false |
||||
end |
||||
|
||||
_ -> |
||||
false |
||||
end |
||||
end |
||||
end |
@ -1,16 +0,0 @@ |
||||
defmodule BlockScoutWeb.CaptchaController do |
||||
use BlockScoutWeb, :controller |
||||
|
||||
alias Plug.Conn |
||||
|
||||
def index(conn, %{"captchaResponse" => captcha_response, "type" => "JSON"}) do |
||||
body = "secret=#{Application.get_env(:block_scout_web, :re_captcha_secret_key)}&response=#{captcha_response}" |
||||
|
||||
headers = [{"Content-type", "application/x-www-form-urlencoded"}] |
||||
|
||||
case HTTPoison.post("https://www.google.com/recaptcha/api/siteverify", body, headers, []) do |
||||
{:ok, %HTTPoison.Response{status_code: status_code, body: body}} -> |
||||
Conn.resp(conn, status_code, body) |
||||
end |
||||
end |
||||
end |
@ -1,3 +0,0 @@ |
||||
defmodule BlockScoutWeb.CaptchaView do |
||||
use BlockScoutWeb, :view |
||||
end |
Loading…
Reference in new issue