# Exrecaptcha

Simple [ReCaptcha] display/verify code for Elixir applications.
Using Exrecaptcha with a CMS such as [Phoenix] is easy.


## Installation

Set as a dep in your mix.exs and ensure it is running with your app:

  def application do
      # ...
      applications: [:phoenix, :cowboy, :logger, :exrecaptcha]
      # ...
  defp deps do
      {:phoenix, "0.4.1"},
      {:cowboy, "~> 1.0.0"},
      # ...
      {:exrecaptcha, github: "adanselm/exrecaptcha"}

And fetch your project's dependencies:

$ mix deps.get

## Config

In your application's config.exs :

config :exrecaptcha,
  api_config: %{ verify_url: "",
                 public_key: "YOUR_PUBLIC_KEY",
                 private_key: "YOUR_PRIVATE_KEY" }

You can use https instead of http for the `verify_url`.

## Usage

### View

Put this code somewhere in your html template:

<form id="loginForm" name="newuser" method="post" action="/users">
  <%= safe Exrecaptcha.display %>

### Controller

Provided you've set the routing properly, you just have to call

# your post method should route you here:
def create(conn, params) do
  # do stuff, then check for the validity of the captcha
  :ok = verify_captcha(conn, params)

defp verify_captcha(conn, %{"recaptcha_challenge_field" => challenge,
                            "recaptcha_response_field" => response}) do
  remote_ip = conn.remote_ip
  Exrecaptcha.verify(remote_ip, challenge, response)


- No option for recaptcha display can be set yet
- Error handling is quite inexistent (throws RuntimeError)
- No tests (if you have an idea how I can test that, I'm all ears)

## Licensing
Copyright © 2014 [Adrien Anselme]( and [contributors](
This work is free. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2,
as published by Sam Hocevar. See the COPYING file for more details.