No commit activity in last 3 years
No release in over 3 years
Description of GoogleRecaptcha.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 4.2.1, ~> 4.2
>= 1.8.0, ~> 1.8
 Project Readme

google_recaptcha

Use google recaptcha to distinguish signup made between robots and human

Basic setup for using this gem with devise is given below

In your Gemfile

gem 'google_recaptcha'

Create a file in config/initialize/captcha.rb

GoogleRecaptcha.configure do |config|
  config.secret_key = "your secret key"
  config.site_key = "your site key"
end
# app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
  layout "sessions"
  def new
    super

  end

  def create
    recaptch_response = params["g-recaptcha-response"]
    client_id = request.env["REMOTE_ADDR"]
    if GoogleRecaptcha::Verification.verify_human(recaptch_response, client_id)
      # if verified by google then call devise registration create action
      super
    else
      resource = build_resource(user_params)
      resource.valid?
      resource.errors.add(:base, "Failed to prove you are human. Please try again")
      render :new
    end
  end

  def update
    super
  end

  def user_params
    params.require(:user).permit(:username, :email, :password, :password_confirmation)
  end
end

Paste this snippet before the closing tag on your HTML template:

<script src='https://www.google.com/recaptcha/api.js'></script>

#include this snippet in the signup form

<%= recaptcha_html %>