aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Alekseev <justmichael@mail.ru>2015-09-05 21:39:59 +0600
committerMichael Alekseev <justmichael@mail.ru>2015-09-05 21:39:59 +0600
commitbf757e89043d32126b4afb5c6023518ff668e248 (patch)
tree7166564052ceb7e7910c17d6397f3b97cf8649bd
parente92c5630195e583362f851f5e88c886431bacbc5 (diff)
downloadrecaptcha-bf757e89043d32126b4afb5c6023518ff668e248.tar.gz
recaptcha-bf757e89043d32126b4afb5c6023518ff668e248.tar.xz
don't send request if response is nil
-rw-r--r--lib/recaptcha.ex20
-rw-r--r--mix.exs2
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/recaptcha.ex b/lib/recaptcha.ex
index c9abf38..7090723 100644
--- a/lib/recaptcha.ex
+++ b/lib/recaptcha.ex
@@ -5,17 +5,37 @@ defmodule Recaptcha do
EEx.function_from_file :defp, :render_template, "lib/template.html.eex", [:assigns]
+ @doc """
+ Returns a string with reCAPTCHA code
+
+ To convert the string to html code, use Phoenix.HTML.Raw/1 method
+ """
def display(options \\ []) do
public_key = options[:public_key] || config.public_key
render_template(public_key: public_key, options: options)
end
+ @doc """
+ Verifies reCAPTCHA response string.
+
+ The function returns :ok or :error, depending on the verification's result
+
+ :ok is returned when the response code was successfully verified
+
+ :error is returned when the response is nil or if the reCAPTCHA server returned
+ a missing-input-response or invalid-input-response code
+
+ The function raises RuntimeError if the server returned a missing-input-secret or invalid-input-secret
+ code
+ """
def verify(remote_ip, response, options \\ [])
def verify(remote_ip, response, options) when is_tuple(remote_ip) do
verify(:inet_parse.ntoa(remote_ip), response, options)
end
+ def verify(remote_ip, nil = response, options), do: :error
+
def verify(remote_ip, response, options) do
case api_response(remote_ip, response, options) do
%{"success" => true} ->
diff --git a/mix.exs b/mix.exs
index 2a4579a..9e9b640 100644
--- a/mix.exs
+++ b/mix.exs
@@ -3,7 +3,7 @@ defmodule Recaptcha.Mixfile do
def project do
[app: :recaptcha,
- version: "1.0.0",
+ version: "1.0.1",
elixir: "~> 1.0.0",
description: description,
deps: deps,