Coder Social home page Coder Social logo

adanselm / exrecaptcha Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 1.0 173 KB

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

License: Do What The F*ck You Want To Public License

Elixir 100.00%

exrecaptcha's Introduction

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]
      # ...
    ]
  end

  defp deps do
    [
      {:phoenix, "0.5.0"},
      {:cowboy, "~> 1.0.0"},
      #...
      {:ibrowse, github: "cmullaparthi/ibrowse", tag: "v4.1.0"},
      {:exrecaptcha, "~> 0.0.3"}
    ]
  end

And fetch your project's dependencies:

$ mix deps.get

Config

In your application's config.exs :

config :exrecaptcha,
  api_config: %{ verify_url: "http://www.google.com/recaptcha/api/verify",
                 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 %>
  ...
</form>

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)
end

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

##TODO

  • No option for recaptcha display can be set yet
  • Error handling is quite inexistent (throws RuntimeError)
  • No tests

Changelog

  • 0.0.3: Update HTTPotion dependency, avoiding elixir version warnings
  • 0.0.2: Use HTTPS by default
  • 0.0.1: Initial release

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.

exrecaptcha's People

Contributors

adanselm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

exrecaptcha's Issues

Recaptcha 2

Does this work with V2?
I am passing the challenge from Frontend to the API, and in the API I need to evaluate it.

What should I put in the recaptcha_response_field ?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.